美文网首页dockeralreadycentos
CentOS快速安装docker

CentOS快速安装docker

作者: 简单点的笨演员 | 来源:发表于2022-10-11 15:37 被阅读0次

docker官方提供了方便的docker安装脚本,我们直接使用即可快速安装docker。执行安装脚本需要以root登录。

  1. 使用官方脚本安装 docker-ce
[root@VM-0-11-centos ~]# curl -fsSL https://get.docker.com -o get-docker.sh
[root@VM-0-11-centos ~]# sudo sh get-docker.sh
 Executing docker install script, commit: 4f282167c425347a931ccfd95cc91fab041d414f
Warning: the "docker" command appears to already exist on this system.

If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.

If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.

You may press Ctrl+C now to abort this script.
+ sleep 20
+ sh -c 'yum install -y -q yum-utils'

Installed:
  yum-utils-4.0.21-14.1.el8.noarch                                                                  

+ sh -c 'yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo'
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
CentOS-8.5.2111 - Base - mirrors.aliyun.com                          52 kB/s | 3.9 kB     00:00    
CentOS-8.5.2111 - Extras - mirrors.aliyun.com                        23 kB/s | 1.5 kB     00:00    
CentOS-8.5.2111 - AppStream - mirrors.aliyun.com                     54 kB/s | 4.3 kB     00:00    
EPEL for redhat/centos 8 - x86_64                                    74 kB/s | 4.7 kB     00:00    
CentOS Stream 8 - AppStream                                         8.3 kB/s | 4.4 kB     00:00    
CentOS Stream 8 - BaseOS                                            9.2 kB/s | 3.9 kB     00:00    
CentOS Stream 8 - Extras common packages                            3.2 kB/s | 3.0 kB     00:00    
Docker CE Stable - x86_64                                            15 kB/s | 3.5 kB     00:00    
Extra Packages for Enterprise Linux Modular 8 - x86_64              5.6 kB/s | 9.6 kB     00:01    
Metadata cache created.
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-scan-plugin docker-compose-plugin docker-ce-rootless-extras'

Installed:
  docker-compose-plugin-2.10.2-3.el8.x86_64                                                         


================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

    dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.


To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
         to root access on the host. Refer to the 'Docker daemon attack surface'
         documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================
  1. 配置docker镜像源
mkdir /etc/docker
touch  /etc/docker/daemon.json
cat > /etc/docker/daemon.json

输入上面命令后,粘贴下面shell中,再按ctrl+d结束。

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] 
} 
  1. 启动docker服务
sudo systemctl start docker
  1. 查看一下docker版本
[root@VM-0-11-centos ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.18
 API version:       1.41
 Go version:        go1.18.6
 Git commit:        b40c2f6
 Built:             Thu Sep  8 23:11:56 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.18
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.6
  Git commit:       e42327a
  Built:            Thu Sep  8 23:10:04 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
  1. 跑一下docker版本的hello world
[root@VM-0-11-centos ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:62af9efd515a25f84961b70f973a798d2eca956b1b2b026d0a4a63a3b0b6a3f2
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
  docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

参考

Docker学习笔记二:Docker设置镜像源 - 零下一度的微笑 - 博客园 (cnblogs.com)
Install Docker Engine on CentOS | Docker Documentation

相关文章

网友评论

    本文标题:CentOS快速安装docker

    本文链接:https://www.haomeiwen.com/subject/zkeaartx.html