centos 7 安装Docker

一、安装Docker

sudo yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@dbnode8 system]# sudo yum -y install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:20.10.10-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.4.1 for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.10-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package containerd.io.x86_64 0:1.4.11-3.1.el7 will be installed
---> Package docker-ce-cli.x86_64 1:20.10.10-3.el7 will be installed
--> Processing Dependency: docker-scan-plugin(x86-64) for package: 1:docker-ce-cli-20.10.10-3.el7.x86_64
---> Package docker-ce-rootless-extras.x86_64 0:20.10.10-3.el7 will be installed
--> Running transaction check
---> Package docker-scan-plugin.x86_64 0:0.9.0-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================
 Package                                 Arch                 Version                                   Repository                      Size
=============================================================================================================================================
Installing:
 docker-ce                               x86_64               3:20.10.10-3.el7                          docker-ce-stable                23 M
Installing for dependencies:
 container-selinux                       noarch               2:2.119.2-1.911c772.el7_8                 extras                          40 k
 containerd.io                           x86_64               1.4.11-3.1.el7                            docker-ce-stable                28 M
 docker-ce-cli                           x86_64               1:20.10.10-3.el7                          docker-ce-stable                29 M
 docker-ce-rootless-extras               x86_64               20.10.10-3.el7                            docker-ce-stable               8.0 M
 docker-scan-plugin                      x86_64               0.9.0-3.el7                               docker-ce-stable               3.7 M

Transaction Summary
=============================================================================================================================================
Install  1 Package (+5 Dependent packages)

Total download size: 92 M
Installed size: 376 M
Downloading packages:
(1/6): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                                           |  40 kB  00:00:00     
(2/6): docker-ce-20.10.10-3.el7.x86_64.rpm                                                                            |  23 MB  00:00:01     
(3/6): docker-ce-cli-20.10.10-3.el7.x86_64.rpm                                                                        |  29 MB  00:00:01     
(4/6): docker-ce-rootless-extras-20.10.10-3.el7.x86_64.rpm                                                            | 8.0 MB  00:00:00     
(5/6): docker-scan-plugin-0.9.0-3.el7.x86_64.rpm                                                                      | 3.7 MB  00:00:00     
(6/6): containerd.io-1.4.11-3.1.el7.x86_64.rpm                                                                        |  28 MB  00:00:08     
---------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                         11 MB/s |  92 MB  00:00:08     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                        1/6 
setsebool:  SELinux is disabled.
  Installing : containerd.io-1.4.11-3.1.el7.x86_64                                                                                       2/6 
  Installing : 1:docker-ce-cli-20.10.10-3.el7.x86_64                                                                                     3/6 
  Installing : docker-scan-plugin-0.9.0-3.el7.x86_64                                                                                     4/6 
  Installing : 3:docker-ce-20.10.10-3.el7.x86_64                                                                                         5/6 
  Installing : docker-ce-rootless-extras-20.10.10-3.el7.x86_64                                                                           6/6 
  Verifying  : docker-ce-rootless-extras-20.10.10-3.el7.x86_64                                                                           1/6 
  Verifying  : docker-scan-plugin-0.9.0-3.el7.x86_64                                                                                     2/6 
  Verifying  : 3:docker-ce-20.10.10-3.el7.x86_64                                                                                         3/6 
  Verifying  : containerd.io-1.4.11-3.1.el7.x86_64                                                                                       4/6 
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                        5/6 
  Verifying  : 1:docker-ce-cli-20.10.10-3.el7.x86_64                                                                                     6/6 

Installed:
  docker-ce.x86_64 3:20.10.10-3.el7                                                                                                          

Dependency Installed:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8    containerd.io.x86_64 0:1.4.11-3.1.el7      docker-ce-cli.x86_64 1:20.10.10-3.el7   
  docker-ce-rootless-extras.x86_64 0:20.10.10-3.el7     docker-scan-plugin.x86_64 0:0.9.0-3.el7   

Complete!

安装成功!

二、开启Docker

sudo systemctl start docker

测试:docker run hello-world

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
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

systemctl stop docker

四、重启Docker

systemctl restart docker

五、配置镜像加速文件

国内网络较慢,拉取docker镜像比较慢,因此需要配置镜像加速文件 /etc/docker/daemon.json

vi /etc/docker/daemon.json

修改daemon.json文件如下所示:

{
"registry-mirrors":["https://tnxkcsol.mirror.aliyuncs.com"]
}

至此,Docker安装成功!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值