CentOS7安装Docker

【提示:docker-io是早期版本,docker-ce是社区版,docker-ee是企业版】

检查内核版本:需要大于3.0

[root@localhost admin]# uname -r
3.10.0-693.el7.x86_64

==================================2019-08-30更新

看了下官网,还是按照官网的来:

1. 先移除老的docker版本

yum remove docker \
           docker-client \
           docker-client-latest \
           docker-common \
           docker-latest \
           docker-latest-logrotate \
           docker-logrotate \
           docker-engine

2. 设置yum Repository。(这一步可省略,仅仅为了下载快一点)

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

国内yum源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3. 列出docker-ce(社区版)的列表

[root@localhost admin]# yum list docker-ce --showduplicates | sort -r
 * updates: centos.ustc.edu.cn
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
 * extras: mirrors.cqu.edu.cn
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
 * base: mirrors.nju.edu.cn
Available Packages

4. 安装

# 你可以安装想要的版本
yum install -y docker-ce-<VERSION_STRING>

如何找出版本号呢,比如 3:19.03.1-3.el7  ,版本号就是 19.03.1

我们还是直接安装吧(默认安装最新的)

[root@localhost admin]# yum -y install docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.1-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.1-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.1-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.1-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.66-1.el7 will be updated
---> Package container-selinux.noarch 2:2.107-1.el7_6 will be an update
--> Processing Dependency: selinux-policy-targeted >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-1.el7_6.noarch
--> Processing Dependency: selinux-policy-base >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-1.el7_6.noarch
--> Processing Dependency: selinux-policy >= 3.13.1-216.el7 for package: 2:container-selinux-2.107-1.el7_6.noarch
---> Package containerd.io.x86_64 0:1.2.6-3.3.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.1-3.el7 will be installed
--> Running transaction check
---> Package selinux-policy.noarch 0:3.13.1-192.el7_5.4 will be updated
---> Package selinux-policy.noarch 0:3.13.1-229.el7_6.15 will be an update
--> Processing Dependency: policycoreutils >= 2.5-24 for package: selinux-policy-3.13.1-229.el7_6.15.noarch
--> Processing Dependency: libsemanage >= 2.5-13 for package: selinux-policy-3.13.1-229.el7_6.15.noarch
---> Package selinux-policy-targeted.noarch 0:3.13.1-192.el7_5.4 will be updated
---> Package selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.15 will be an update
--> Running transaction check
---> Package libsemanage.x86_64 0:2.5-11.el7 will be updated
--> Processing Dependency: libsemanage = 2.5-11.el7 for package: libsemanage-python-2.5-11.el7.x86_64
---> Package libsemanage.x86_64 0:2.5-14.el7 will be an update
--> Processing Dependency: libsepol >= 2.5-10 for package: libsemanage-2.5-14.el7.x86_64
--> Processing Dependency: libselinux >= 2.5-14 for package: libsemanage-2.5-14.el7.x86_64
---> Package policycoreutils.x86_64 0:2.5-22.el7 will be updated
--> Processing Dependency: policycoreutils = 2.5-22.el7 for package: policycoreutils-python-2.5-22.el7.x86_64
---> Package policycoreutils.x86_64 0:2.5-29.el7_6.1 will be an update
--> Processing Dependency: libselinux-utils >= 2.5-14 for package: policycoreutils-2.5-29.el7_6.1.x86_64
--> Running transaction check
---> Package libselinux.x86_64 0:2.5-12.el7 will be updated
--> Processing Dependency: libselinux(x86-64) = 2.5-12.el7 for package: libselinux-python-2.5-12.el7.x86_64
---> Package libselinux.x86_64 0:2.5-14.1.el7 will be an update
---> Package libselinux-utils.x86_64 0:2.5-12.el7 will be updated
---> Package libselinux-utils.x86_64 0:2.5-14.1.el7 will be an update
---> Package libsemanage-python.x86_64 0:2.5-11.el7 will be updated
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be an update
---> Package libsepol.x86_64 0:2.5-8.1.el7 will be updated
---> Package libsepol.x86_64 0:2.5-10.el7 will be an update
---> Package policycoreutils-python.x86_64 0:2.5-22.el7 will be updated
---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be an update
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64
--> Running transaction check
---> Package libselinux-python.x86_64 0:2.5-12.el7 will be updated
---> Package libselinux-python.x86_64 0:2.5-14.1.el7 will be an update
---> Package setools-libs.x86_64 0:3.3.8-2.el7 will be updated
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================
 Package                                             Arch                               Version                                            Repository                                    Size
==============================================================================================================================================================================================
Installing:
 docker-ce                                           x86_64                             3:19.03.1-3.el7                                    docker-ce-stable                              24 M
Installing for dependencies:
 containerd.io                                       x86_64                             1.2.6-3.3.el7                                      docker-ce-stable                              26 M
 docker-ce-cli                                       x86_64                             1:19.03.1-3.el7                                    docker-ce-stable                              39 M
Updating for dependencies:
 container-selinux                                   noarch                             2:2.107-1.el7_6                                    extras                                        39 k
 libselinux                                          x86_64                             2.5-14.1.el7                                       base                                         162 k
 libselinux-python                                   x86_64                             2.5-14.1.el7                                       base                                         235 k
 libselinux-utils                                    x86_64                             2.5-14.1.el7                                       base                                         151 k
 libsemanage                                         x86_64                             2.5-14.el7                                         base                                         151 k
 libsemanage-python                                  x86_64                             2.5-14.el7                                         base                                         113 k
 libsepol                                            x86_64                             2.5-10.el7                                         base                                         297 k
 policycoreutils                                     x86_64                             2.5-29.el7_6.1                                     updates                                      916 k
 policycoreutils-python                              x86_64                             2.5-29.el7_6.1                                     updates                                      456 k
 selinux-policy                                      noarch                             3.13.1-229.el7_6.15                                updates                                      484 k
 selinux-policy-targeted                             noarch                             3.13.1-229.el7_6.15                                updates                                      6.9 M
 setools-libs                                        x86_64                             3.3.8-4.el7                                        base                                         620 k

Transaction Summary
==============================================================================================================================================================================================
Install  1 Package  (+ 2 Dependent packages)
Upgrade             ( 12 Dependent packages)

Total size: 100 M
Total download size: 98 M
Downloading packages:
No Presto metadata available for base
Not downloading deltainfo for extras, MD is 73 k and rpms are 39 k
(1/8): container-selinux-2.107-1.el7_6.noarch.rpm                                                                                                                      |  39 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.1-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY       ] 709 kB/s |  47 MB  00:01:13 ETA 
Public key for docker-ce-19.03.1-3.el7.x86_64.rpm is not installed
(2/8): docker-ce-19.03.1-3.el7.x86_64.rpm                                                                                                                              |  24 MB  00:01:08     
(3/8): selinux-policy-3.13.1-229.el7_6.15.noarch.rpm                                                                                                                   | 484 kB  00:00:00     
(4/8): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                                                                        | 113 kB  00:00:00     
(5/8): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                                                                             | 620 kB  00:00:01     
(6/8): selinux-policy-targeted-3.13.1-229.el7_6.15.noarch.rpm                                                                                                          | 6.9 MB  00:00:04     
(7/8): containerd.io-1.2.6-3.3.el7.x86_64.rpm                                                                                                                          |  26 MB  00:01:18     
(8/8): docker-ce-cli-19.03.1-3.el7.x86_64.rpm                                                                                                                          |  39 MB  00:01:48     
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                         565 kB/s |  98 MB  00:02:57     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libsepol-2.5-10.el7.x86_64                                                                                                                                                1/27 
  Updating   : libselinux-2.5-14.1.el7.x86_64                                                                                                                                            2/27 
  Updating   : libsemanage-2.5-14.el7.x86_64                                                                                                                                             3/27 
  Updating   : libselinux-utils-2.5-14.1.el7.x86_64                                                                                                                                      4/27 
  Updating   : policycoreutils-2.5-29.el7_6.1.x86_64                                                                                                                                     5/27 
  Updating   : selinux-policy-3.13.1-229.el7_6.15.noarch                                                                                                                                 6/27 
  Updating   : selinux-policy-targeted-3.13.1-229.el7_6.15.noarch                                                                                                                        7/27 
  Updating   : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                      8/27 
  Updating   : libselinux-python-2.5-14.1.el7.x86_64                                                                                                                                     9/27 
  Updating   : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                          10/27 
  Updating   : policycoreutils-python-2.5-29.el7_6.1.x86_64                                                                                                                             11/27 
  Updating   : 2:container-selinux-2.107-1.el7_6.noarch                                                                                                                                 12/27 
  Installing : containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                                       13/27 
  Installing : 1:docker-ce-cli-19.03.1-3.el7.x86_64                                                                                                                                     14/27 
  Installing : 3:docker-ce-19.03.1-3.el7.x86_64                                                                                                                                         15/27 
  Cleanup    : 2:container-selinux-2.66-1.el7.noarch                                                                                                                                    16/27 
  Cleanup    : selinux-policy-targeted-3.13.1-192.el7_5.4.noarch                                                                                                                        17/27 
  Cleanup    : policycoreutils-python-2.5-22.el7.x86_64                                                                                                                                 18/27 
  Cleanup    : selinux-policy-3.13.1-192.el7_5.4.noarch                                                                                                                                 19/27 
  Cleanup    : policycoreutils-2.5-22.el7.x86_64                                                                                                                                        20/27 
  Cleanup    : libselinux-utils-2.5-12.el7.x86_64                                                                                                                                       21/27 
  Cleanup    : setools-libs-3.3.8-2.el7.x86_64                                                                                                                                          22/27 
  Cleanup    : libselinux-python-2.5-12.el7.x86_64                                                                                                                                      23/27 
  Cleanup    : libsemanage-python-2.5-11.el7.x86_64                                                                                                                                     24/27 
  Cleanup    : libsemanage-2.5-11.el7.x86_64                                                                                                                                            25/27 
  Cleanup    : libselinux-2.5-12.el7.x86_64                                                                                                                                             26/27 
  Cleanup    : libsepol-2.5-8.1.el7.x86_64                                                                                                                                              27/27 
  Verifying  : policycoreutils-2.5-29.el7_6.1.x86_64                                                                                                                                     1/27 
  Verifying  : 3:docker-ce-19.03.1-3.el7.x86_64                                                                                                                                          2/27 
  Verifying  : libselinux-python-2.5-14.1.el7.x86_64                                                                                                                                     3/27 
  Verifying  : selinux-policy-3.13.1-229.el7_6.15.noarch                                                                                                                                 4/27 
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                           5/27 
  Verifying  : policycoreutils-python-2.5-29.el7_6.1.x86_64                                                                                                                              6/27 
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                      7/27 
  Verifying  : libsemanage-2.5-14.el7.x86_64                                                                                                                                             8/27 
  Verifying  : libsepol-2.5-10.el7.x86_64                                                                                                                                                9/27 
  Verifying  : containerd.io-1.2.6-3.3.el7.x86_64                                                                                                                                       10/27 
  Verifying  : selinux-policy-targeted-3.13.1-229.el7_6.15.noarch                                                                                                                       11/27 
  Verifying  : libselinux-utils-2.5-14.1.el7.x86_64                                                                                                                                     12/27 
  Verifying  : 2:container-selinux-2.107-1.el7_6.noarch                                                                                                                                 13/27 
  Verifying  : 1:docker-ce-cli-19.03.1-3.el7.x86_64                                                                                                                                     14/27 
  Verifying  : libselinux-2.5-14.1.el7.x86_64                                                                                                                                           15/27 
  Verifying  : libsemanage-python-2.5-11.el7.x86_64                                                                                                                                     16/27 
  Verifying  : libsemanage-2.5-11.el7.x86_64                                                                                                                                            17/27 
  Verifying  : libselinux-python-2.5-12.el7.x86_64                                                                                                                                      18/27 
  Verifying  : selinux-policy-3.13.1-192.el7_5.4.noarch                                                                                                                                 19/27 
  Verifying  : setools-libs-3.3.8-2.el7.x86_64                                                                                                                                          20/27 
  Verifying  : policycoreutils-2.5-22.el7.x86_64                                                                                                                                        21/27 
  Verifying  : selinux-policy-targeted-3.13.1-192.el7_5.4.noarch                                                                                                                        22/27 
  Verifying  : policycoreutils-python-2.5-22.el7.x86_64                                                                                                                                 23/27 
  Verifying  : 2:container-selinux-2.66-1.el7.noarch                                                                                                                                    24/27 
  Verifying  : libsepol-2.5-8.1.el7.x86_64                                                                                                                                              25/27 
  Verifying  : libselinux-2.5-12.el7.x86_64                                                                                                                                             26/27 
  Verifying  : libselinux-utils-2.5-12.el7.x86_64                                                                                                                                       27/27 

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

Dependency Installed:
  containerd.io.x86_64 0:1.2.6-3.3.el7                                                          docker-ce-cli.x86_64 1:19.03.1-3.el7                                                         

Dependency Updated:
  container-selinux.noarch 2:2.107-1.el7_6        libselinux.x86_64 0:2.5-14.1.el7             libselinux-python.x86_64 0:2.5-14.1.el7               libselinux-utils.x86_64 0:2.5-14.1.el7  
  libsemanage.x86_64 0:2.5-14.el7                 libsemanage-python.x86_64 0:2.5-14.el7       libsepol.x86_64 0:2.5-10.el7                          policycoreutils.x86_64 0:2.5-29.el7_6.1 
  policycoreutils-python.x86_64 0:2.5-29.el7_6.1  selinux-policy.noarch 0:3.13.1-229.el7_6.15  selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.15  setools-libs.x86_64 0:3.3.8-4.el7       

Complete!

启动

简略版本信息

配置一下国内镜像

[root@localhost admin]# vim /etc/docker/daemon.json
{
  "registry-mirrors": ["https://2148hpzn.mirror.aliyuncs.com","http://hub-mirror.c.163.com"]
}
# 重启服务
systemctl daemon-reload
systemctl restart docker

运行hello-world

==================================更新完

第一步、切换成root用户并update yum

yum update

第二步、安装Docker

yum -y install docker-io

以下是运行结果

[root@localhost admin]# yum -y install docker-io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 2:1.13.1-68.gitdded712.el7.centos will be installed
--> Processing Dependency: docker-common = 2:1.13.1-68.gitdded712.el7.centos for package: 2:docker-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: docker-client = 2:1.13.1-68.gitdded712.el7.centos for package: 2:docker-1.13.1-68.gitdded712.el7.centos.x86_64
--> Running transaction check
---> Package docker-client.x86_64 2:1.13.1-68.gitdded712.el7.centos will be installed
---> Package docker-common.x86_64 2:1.13.1-68.gitdded712.el7.centos will be installed
--> Processing Dependency: skopeo-containers >= 1:0.1.26-2 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: oci-umount >= 2:2.3.3-3 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: oci-systemd-hook >= 1:0.1.4-9 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: oci-register-machine >= 1:0-5.13 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: container-storage-setup >= 0.9.0-1 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Processing Dependency: container-selinux >= 2:2.51-1 for package: 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.66-1.el7 will be installed
---> Package container-storage-setup.noarch 0:0.10.0-1.gitdf0dcd5.el7 will be installed
---> Package oci-register-machine.x86_64 1:0-6.git2b44233.el7 will be installed
---> Package oci-systemd-hook.x86_64 1:0.1.16-1.git05bd9a0.el7 will be installed
---> Package oci-umount.x86_64 2:2.3.3-3.gite3c9055.el7 will be installed
---> Package skopeo-containers.x86_64 1:0.1.31-1.dev.gitae64ff7.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================================
 Package                                             Arch                               Version                                                           Repository                          Size
===================================================================================================================================================================================================
Installing:
 docker                                              x86_64                             2:1.13.1-68.gitdded712.el7.centos                                 extras                              16 M
Installing for dependencies:
 container-selinux                                   noarch                             2:2.66-1.el7                                                      extras                              35 k
 container-storage-setup                             noarch                             0.10.0-1.gitdf0dcd5.el7                                           extras                              34 k
 docker-client                                       x86_64                             2:1.13.1-68.gitdded712.el7.centos                                 extras                             3.8 M
 docker-common                                       x86_64                             2:1.13.1-68.gitdded712.el7.centos                                 extras                              90 k
 oci-register-machine                                x86_64                             1:0-6.git2b44233.el7                                              extras                             1.1 M
 oci-systemd-hook                                    x86_64                             1:0.1.16-1.git05bd9a0.el7                                         extras                              33 k
 oci-umount                                          x86_64                             2:2.3.3-3.gite3c9055.el7                                          extras                              32 k
 skopeo-containers                                   x86_64                             1:0.1.31-1.dev.gitae64ff7.el7.centos                              extras                              17 k

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

Total download size: 21 M
Installed size: 73 M
Downloading packages:
(1/9): container-selinux-2.66-1.el7.noarch.rpm                                                                                                                              |  35 kB  00:00:00     
(2/9): container-storage-setup-0.10.0-1.gitdf0dcd5.el7.noarch.rpm                                                                                                           |  34 kB  00:00:00     
(3/9): docker-common-1.13.1-68.gitdded712.el7.centos.x86_64.rpm                                                                                                             |  90 kB  00:00:00     
(4/9): oci-systemd-hook-0.1.16-1.git05bd9a0.el7.x86_64.rpm                                                                                                                  |  33 kB  00:00:00     
(5/9): oci-umount-2.3.3-3.gite3c9055.el7.x86_64.rpm                                                                                                                         |  32 kB  00:00:00     
(6/9): skopeo-containers-0.1.31-1.dev.gitae64ff7.el7.centos.x86_64.rpm                                                                                                      |  17 kB  00:00:00     
(7/9): oci-register-machine-0-6.git2b44233.el7.x86_64.rpm                                                                                                                   | 1.1 MB  00:00:01     
(8/9): docker-client-1.13.1-68.gitdded712.el7.centos.x86_64.rpm                                                                                                             | 3.8 MB  00:00:02     
(9/9): docker-1.13.1-68.gitdded712.el7.centos.x86_64.rpm                                                                                                                    |  16 MB  00:00:13     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                              1.6 MB/s |  21 MB  00:00:13     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:skopeo-containers-0.1.31-1.dev.gitae64ff7.el7.centos.x86_64                                                                                                                   1/9 
  Installing : 2:container-selinux-2.66-1.el7.noarch                                                                                                                                           2/9 
  Installing : 2:oci-umount-2.3.3-3.gite3c9055.el7.x86_64                                                                                                                                      3/9 
  Installing : 1:oci-register-machine-0-6.git2b44233.el7.x86_64                                                                                                                                4/9 
  Installing : 1:oci-systemd-hook-0.1.16-1.git05bd9a0.el7.x86_64                                                                                                                               5/9 
  Installing : container-storage-setup-0.10.0-1.gitdf0dcd5.el7.noarch                                                                                                                          6/9 
  Installing : 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                          7/9 
  Installing : 2:docker-client-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                          8/9 
  Installing : 2:docker-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                                 9/9 
  Verifying  : container-storage-setup-0.10.0-1.gitdf0dcd5.el7.noarch                                                                                                                          1/9 
  Verifying  : 1:oci-systemd-hook-0.1.16-1.git05bd9a0.el7.x86_64                                                                                                                               2/9 
  Verifying  : 1:oci-register-machine-0-6.git2b44233.el7.x86_64                                                                                                                                3/9 
  Verifying  : 2:oci-umount-2.3.3-3.gite3c9055.el7.x86_64                                                                                                                                      4/9 
  Verifying  : 2:docker-client-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                          5/9 
  Verifying  : 2:container-selinux-2.66-1.el7.noarch                                                                                                                                           6/9 
  Verifying  : 1:skopeo-containers-0.1.31-1.dev.gitae64ff7.el7.centos.x86_64                                                                                                                   7/9 
  Verifying  : 2:docker-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                                 8/9 
  Verifying  : 2:docker-common-1.13.1-68.gitdded712.el7.centos.x86_64                                                                                                                          9/9 

Installed:
  docker.x86_64 2:1.13.1-68.gitdded712.el7.centos                                                                                                                                                  

Dependency Installed:
  container-selinux.noarch 2:2.66-1.el7                         container-storage-setup.noarch 0:0.10.0-1.gitdf0dcd5.el7             docker-client.x86_64 2:1.13.1-68.gitdded712.el7.centos       
  docker-common.x86_64 2:1.13.1-68.gitdded712.el7.centos        oci-register-machine.x86_64 1:0-6.git2b44233.el7                     oci-systemd-hook.x86_64 1:0.1.16-1.git05bd9a0.el7            
  oci-umount.x86_64 2:2.3.3-3.gite3c9055.el7                    skopeo-containers.x86_64 1:0.1.31-1.dev.gitae64ff7.el7.centos       

Complete!

第三步、运行Docker

[root@localhost admin]# systemctl start docker

第四步、运行Hello-Word

[root@localhost admin]# docker run hello-world
Unable to find image 'hello-world:latest' locally
Trying to pull repository docker.io/library/hello-world ... 
latest: Pulling from docker.io/library/hello-world
9db2ca6ccae0: Pull complete 
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
Status: Downloaded newer image for docker.io/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/engine/userguide/

查看状态

[root@localhost admin]# systemctl status docker

查看docker命令

[root@localhost admin]# docker

Usage:    docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -D, --debug              Enable debug mode
      --help               Print usage
  -H, --host list          Daemon socket(s) to connect to (default [])
  -l, --log-level string   Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/root/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/root/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/root/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  volume      Manage volumes

Commands:
  attach      Attach to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.

查看版本

[root@localhost admin]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      dded712/1.13.1
 Built:           Tue Jul 17 18:34:48 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-68.gitdded712.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      dded712/1.13.1
 Built:           Tue Jul 17 18:34:48 2018
 OS/Arch:         linux/amd64
 Experimental:    false
[root@localhost admin]# 

列出所有已存在的镜像

[root@localhost admin]# docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
docker.io/hello-world   latest              2cb0d9787c4d        4 weeks ago         1.85 kB

查询镜像:比如mongo

[root@localhost admin]# docker search mongo
INDEX       NAME                                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/mongo                               MongoDB document databases provide high av...   4821      [OK]       
docker.io   docker.io/mongo-express                       Web-based MongoDB admin interface, written...   279       [OK]       
docker.io   docker.io/tutum/mongodb                       MongoDB Docker image – listens in port 270...   225                  [OK]
docker.io   docker.io/mvertes/alpine-mongo                light MongoDB container                         78                   [OK]
docker.io   docker.io/mongoclient/mongoclient             Official docker image for Mongoclient, fea...   53                   [OK]
docker.io   docker.io/bitnami/mongodb                     Bitnami MongoDB Docker Image                    44                   [OK]
docker.io   docker.io/frodenas/mongodb                    A Docker Image for MongoDB                      17                   [OK]
docker.io   docker.io/mongooseim/mongooseim               Small docker image for MongooseIM - robust...   16                   
docker.io   docker.io/cvallance/mongo-k8s-sidecar         Kubernetes side car to setup and maintain ...   8                    [OK]
docker.io   docker.io/centos/mongodb-26-centos7           MongoDB NoSQL database server                   5                    
docker.io   docker.io/centos/mongodb-32-centos7           MongoDB NoSQL database server                   5                    
docker.io   docker.io/istepanov/mongodump                 Docker image with mongodump running as a c...   5                    [OK]
docker.io   docker.io/eses/mongodb_exporter               mongodb exporter for prometheus                 4                    [OK]
docker.io   docker.io/khezen/mongo                        MongoDB Docker image supporting RocksDB st...   4                    [OK]
docker.io   docker.io/neowaylabs/mongodb-mms-agent        This Docker image with MongoDB Monitoring ...   2                    [OK]
docker.io   docker.io/19hz/mongo-container                Mongodb replicaset for coreos                   1                    [OK]
docker.io   docker.io/centos/mongodb-34-centos7           MongoDB NoSQL database server                   1                    
docker.io   docker.io/centos/mongodb-36-centos7           MongoDB NoSQL database server                   1                    
docker.io   docker.io/circleci/mongo                      CircleCI images for MongoDB                     1                    [OK]
docker.io   docker.io/ekesken/mongo                       docker image for mongo that is configurabl...   1                    [OK]
docker.io   docker.io/openshift/mongodb-24-centos7        DEPRECATED: A Centos7 based MongoDB v2.4 i...   1                    
docker.io   docker.io/webhippie/mongodb                   Docker images for mongodb                       1                    [OK]
docker.io   docker.io/amd64/mongo                         MongoDB document databases provide high av...   0                    
docker.io   docker.io/ansibleplaybookbundle/mongodb-apb   An APB to deploy MongoDB.                       0                    [OK]
docker.io   docker.io/quilt/mongo                         MongoDB container for quilt.io                  0                    [OK]

拉取最新的镜像

[root@localhost admin]# docker pull mongo
Using default tag: latest
Trying to pull repository docker.io/library/mongo ... 
latest: Pulling from docker.io/library/mongo
8ee29e426c26: Pull complete 
6e83b260b73b: Pull complete 
e26b65fd1143: Pull complete 
40dca07f8222: Pull complete 
b420ae9e10b3: Pull complete 
f60a3ef68cf9: Pull complete 
4a9eeb4f5b1b: Pull complete 
2b2f33f1e783: Pull complete 
dbadcc13ac8f: Pull complete 
a532ead5a592: Pull complete 
3f1579bbe71b: Pull complete 
f6c26165a602: Pull complete 
f2ea37fea6c8: Pull complete 
0d33fd177178: Pull complete 
Digest: sha256:232dfea36769772372e1784c2248bba53c6bdf0893d82375a3b66c09962b5af9
Status: Downloaded newer image for docker.io/mongo:latest

启动mongo镜像并查看启动情况

docker run --name some-mongo -d mongo:tag

 --name  名字

-d   后台运行容器,并返回容器ID

-v /data/mongo:/data/mongo  将本地/data/mongo 数据目录 挂载到docker 对应的/data/mongo目录上

[root@localhost /]# docker run --name my_mongo -v /data/mongo:/data/mongo -d mongo
6f5b2fdc120f997a6cd945a6aa547012ecad3618ab474376322b1b422292ef15
[root@localhost /]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
6f5b2fdc120f        mongo               "docker-entrypoint..."   4 seconds ago       Up 3 seconds        27017/tcp           my_mongo

进入容器并连接

[root@localhost /]# docker exec -it my_mongo bash
root@6f5b2fdc120f:/# mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] 
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] 
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] 
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] 
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2018-08-13T11:48:33.934+0000 I CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
> exit
bye

 

按Ctrl+P+Q进行退出容器,也可以执行exit命令退出

停止容器【stop后面是NAMES对应的名字

[root@localhost admin]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                      NAMES
dd310d6213a8        mongo               "docker-entrypoint..."   23 minutes ago      Up 23 minutes       0.0.0.0:27017->27017/tcp   nifty_noyce
[root@localhost admin]# docker stop nifty_noyce
nifty_noyce
[root@localhost admin]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

查看所有容器

docker ps -a 

删除所有停止的容器

docker rm $(docker ps -a -q)  

 停止docker

[root@localhost /]# systemctl stop docker
[root@localhost /]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead) since Mon 2018-08-13 08:16:34 EDT; 8s ago
     Docs: http://docs.docker.com
  Process: 36006 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=0/SUCCESS)
 Main PID: 36006 (code=exited, status=0/SUCCESS)

Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.872+0000 I CONTROL  [signalProcessingThread] Shutting down free monitoring
Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.873+0000 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.877+0000 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.911+0000 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.911+0000 I CONTROL  [signalProcessingThread] now exiting
Aug 13 08:16:32 localhost.localdomain dockerd-current[36006]: 2018-08-13T12:16:32.911+0000 I CONTROL  [signalProcessingThread] shutting down with code:0
Aug 13 08:16:33 localhost.localdomain dockerd-current[36006]: time="2018-08-13T08:16:33.076314359-04:00" level=error msg="containerd: deleting container" error="exit status 1: \"con...ailed\\n\""
Aug 13 08:16:33 localhost.localdomain dockerd-current[36006]: time="2018-08-13T08:16:33.205465662-04:00" level=warning msg="6f5b2fdc120f997a6cd945a6aa547012ecad3618ab474376322b1b422...d argument"
Aug 13 08:16:33 localhost.localdomain dockerd-current[36006]: time="2018-08-13T08:16:33.253668366-04:00" level=info msg="stopping containerd after receiving terminated"
Aug 13 08:16:34 localhost.localdomain systemd[1]: Stopped Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

 

posted @ 2018-08-13 20:14  露娜妹  阅读(1360)  评论(0编辑  收藏  举报