CentOS 安裝 Docker CE

版本 釋義
Docker CE 社區版Docker
Docker EE 企業版Docker

前提:

To install Docker CE, you need a maintained version of CentOS 7. Archived versions aren’t supported or tested.

1.安裝Docker存儲庫需要的包

sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2

示例

[root@zaomianbao1 ~]# sudo yum install -y yum-utils \
>   device-mapper-persistent-data \
>   lvm2
Loaded plugins: fastestmirror
base                                                                                                                                                                                        | 3.6 kB  00:00:00     
epel                                                                                                                                                                                        | 4.7 kB  00:00:00     
extras                                                                                                                                                                                      | 3.4 kB  00:00:00     
updates                                                                                                                                                                                     | 3.4 kB  00:00:00     
(1/7): epel/x86_64/group_gz                                                                                                                                                                 |  88 kB  00:00:00     
(2/7): base/7/x86_64/group_gz                                                                                                                                                               | 166 kB  00:00:00     
(3/7): epel/x86_64/updateinfo                                                                                                                                                               | 952 kB  00:00:00     
(4/7): extras/7/x86_64/primary_db                                                                                                                                                           | 156 kB  00:00:00     
(5/7): updates/7/x86_64/primary_db                                                                                                                                                          | 1.3 MB  00:00:00     
(6/7): base/7/x86_64/primary_db                                                                                                                                                             | 6.0 MB  00:00:00     
(7/7): epel/x86_64/primary_db                                                                                                                                                               | 6.6 MB  00:00:00     
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check

2.設置穩定存儲庫

sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo

示例

[root@zaomianbao1 ~]# sudo yum-config-manager \
>     --add-repo \
>     https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
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@zaomianbao1 ~]# sudo yum install docker-ce
Loaded plugins: fastestmirror
docker-ce-stable                                                                                                                                                                            | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/x86_64/updateinfo                                                                                                                                                   |   55 B  00:00:01     
(2/2): docker-ce-stable/x86_64/primary_db                                                                                                                                                   |  20 kB  00:00:02     
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64

3.安裝DOCKER CE

sudo yum install docker-ce

示例

[root@zaomianbao1 ~]# sudo yum install docker-ce
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:18.09.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2.9 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: libseccomp >= 2.3 for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: containerd.io for package: 3:docker-ce-18.09.1-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-18.09.1-3.el7.x86_64

4.啓動Docker

sudo systemctl start docker

示例

[root@zaomianbao1 ~]# sudo systemctl start docker
[root@zaomianbao1 ~]#

5.驗證Docker

sudo docker run hello-world

此命令下載測試映像並在容器中運行它。當容器運行時,它會打印一條信息性消息並退出

示例

[root@zaomianbao1 ~]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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/

[root@zaomianbao1 ~]# 

6.總結

Docker CE 的在CentOS上的整個的安裝流程就是如此

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章