Docker教程 —— CentOS7 精简版安装docker环境 Part 1

原创
2019/08/18 18:36
阅读数 1K

工作准备

1、CentOS 7 虚拟机

2、docker-ce、docker-ce-cli、containerd.ior的rpm安装包

3、配置好虚拟机网络、确保可以更新依赖软件

安装docker

1、进入到docker的rpm安装包所在路径执行以下命令:

# yum -y install *.rpm

Loaded plugins: fastestmirror

Examining containerd.io-1.2.6-3.3.el7.x86_64.rpm: containerd.io-1.2.6-3.3.el7.x86_64

Marking containerd.io-1.2.6-3.3.el7.x86_64.rpm to be installed

Examining docker-ce-19.03.0-3.el7.x86_64.rpm: 3:docker-ce-19.03.0-3.el7.x86_64

Marking docker-ce-19.03.0-3.el7.x86_64.rpm to be installed

Examining docker-ce-cli-19.03.0-3.el7.x86_64.rpm: 1:docker-ce-cli-19.03.0-3.el7.x86_64

Marking docker-ce-cli-19.03.0-3.el7.x86_64.rpm to be installed

Resolving Dependencies

--> Running transaction check

---> Package containerd.io.x86_64 0:1.2.6-3.3.el7 will be installed

--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.6-3.3.el7.x86_64

base                                                                                | 3.6 kB  00:00:00    

extras                                                                              | 3.4 kB  00:00:00    

updates                                                                             | 3.4 kB  00:00:00    

(1/4): extras/7/x86_64/primary_db                                                   | 215 kB  00:00:16    

(2/4): base/7/x86_64/group_gz                                                       | 166 kB  00:00:23    

(3/4): updates/7/x86_64/primary_db                                                  | 7.4 MB  00:00:44    

(4/4): base/7/x86_64/primary_db                                                     | 6.0 MB  00:00:53    

Determining fastest mirrors

 * base: mirrors.cn99.com

 * extras: mirrors.cn99.com

 * updates: mirrors.cn99.com

---> Package docker-ce.x86_64 3:19.03.0-3.el7 will be installed

--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.0-3.el7.x86_64

---> Package docker-ce-cli.x86_64 1:19.03.0-3.el7 will be installed

--> Running transaction check

---> Package container-selinux.noarch 2:2.107-1.el7_6 will be installed

--> 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

--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.107-1.el7_6.noarch

---> Package libcgroup.x86_64 0:0.41-20.el7 will be installed

--> Running transaction check

---> Package policycoreutils-python.x86_64 0:2.5-29.el7_6.1 will be installed

--> Processing Dependency: policycoreutils = 2.5-29.el7_6.1 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-29.el7_6.1.x86_64

---> Package selinux-policy.noarch 0:3.13.1-166.el7 will be updated

---> Package selinux-policy.noarch 0:3.13.1-229.el7_6.15 will be an update

--> 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-166.el7 will be updated

---> Package selinux-policy-targeted.noarch 0:3.13.1-229.el7_6.15 will be an update

--> Running transaction check

---> Package audit-libs-python.x86_64 0:2.8.4-4.el7 will be installed

--> Processing Dependency: audit-libs(x86-64) = 2.8.4-4.el7 for package: audit-libs-python-2.8.4-4.el7.x86_64

---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed

---> Package libsemanage.x86_64 0:2.5-8.el7 will be updated

---> 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 libsemanage-python.x86_64 0:2.5-14.el7 will be installed

---> Package policycoreutils.x86_64 0:2.5-17.1.el7 will be updated

---> 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

---> Package python-IPy.noarch 0:0.75-6.el7 will be installed

---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed

--> Running transaction check

---> Package audit-libs.x86_64 0:2.7.6-3.el7 will be updated

--> Processing Dependency: audit-libs(x86-64) = 2.7.6-3.el7 for package: audit-2.7.6-3.el7.x86_64

---> Package audit-libs.x86_64 0:2.8.4-4.el7 will be an update

---> Package libselinux.x86_64 0:2.5-11.el7 will be updated

--> Processing Dependency: libselinux(x86-64) = 2.5-11.el7 for package: libselinux-python-2.5-11.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-11.el7 will be updated

---> Package libselinux-utils.x86_64 0:2.5-14.1.el7 will be an update

---> Package libsepol.x86_64 0:2.5-6.el7 will be updated

---> Package libsepol.x86_64 0:2.5-10.el7 will be an update

--> Running transaction check

---> Package audit.x86_64 0:2.7.6-3.el7 will be updated

---> Package audit.x86_64 0:2.8.4-4.el7 will be an update

---> Package libselinux-python.x86_64 0:2.5-11.el7 will be updated

---> Package libselinux-python.x86_64 0:2.5-14.1.el7 will be an update

--> Finished Dependency Resolution



Dependencies Resolved



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

 Package                    Arch      Version                 Repository                              Size

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

Installing:

 containerd.io              x86_64    1.2.6-3.3.el7           /containerd.io-1.2.6-3.3.el7.x86_64     96 M

 docker-ce                  x86_64    3:19.03.0-3.el7         /docker-ce-19.03.0-3.el7.x86_64        104 M

 docker-ce-cli              x86_64    1:19.03.0-3.el7         /docker-ce-cli-19.03.0-3.el7.x86_64    169 M

Installing for dependencies:

 audit-libs-python          x86_64    2.8.4-4.el7             base                                    76 k

 checkpolicy                x86_64    2.5-8.el7               base                                   295 k

 container-selinux          noarch    2:2.107-1.el7_6         extras                                  39 k

 libcgroup                  x86_64    0.41-20.el7             base                                    66 k

 libsemanage-python         x86_64    2.5-14.el7              base                                   113 k

 policycoreutils-python     x86_64    2.5-29.el7_6.1          updates                                456 k

 python-IPy                 noarch    0.75-6.el7              base                                    32 k

 setools-libs               x86_64    3.3.8-4.el7             base                                   620 k

Updating for dependencies:

 audit                      x86_64    2.8.4-4.el7             base                                   250 k

 audit-libs                 x86_64    2.8.4-4.el7             base                                   100 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

 libsepol                   x86_64    2.5-10.el7              base                                   297 k

 policycoreutils            x86_64    2.5-29.el7_6.1          updates                                916 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



Transaction Summary

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

Install  3 Packages (+ 8 Dependent packages)

Upgrade             ( 10 Dependent packages)



Total size: 380 M

Total download size: 11 M

Downloading packages:

Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

warning: /var/cache/yum/x86_64/7/base/packages/audit-libs-2.8.4-4.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY

Public key for audit-libs-2.8.4-4.el7.x86_64.rpm is not installed

(1/18): audit-libs-2.8.4-4.el7.x86_64.rpm                                           | 100 kB  00:00:00    

(2/18): libcgroup-0.41-20.el7.x86_64.rpm                                            |  66 kB  00:00:00    

(3/18): checkpolicy-2.5-8.el7.x86_64.rpm                                            | 295 kB  00:00:00    

Public key for container-selinux-2.107-1.el7_6.noarch.rpm is not installed

(4/18): container-selinux-2.107-1.el7_6.noarch.rpm                                  |  39 kB  00:00:00    

(5/18): libselinux-2.5-14.1.el7.x86_64.rpm                                          | 162 kB  00:00:00    

(6/18): libsemanage-2.5-14.el7.x86_64.rpm                                           | 151 kB  00:00:00    

(7/18): libselinux-python-2.5-14.1.el7.x86_64.rpm                                   | 235 kB  00:00:00    

(8/18): libsepol-2.5-10.el7.x86_64.rpm                                              | 297 kB  00:00:00    

(9/18): libsemanage-python-2.5-14.el7.x86_64.rpm                                    | 113 kB  00:00:00    

Public key for policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm is not installedB/s | 2.2 MB  00:00:09 ETA

(10/18): policycoreutils-python-2.5-29.el7_6.1.x86_64.rpm                           | 456 kB  00:00:00    

(11/18): python-IPy-0.75-6.el7.noarch.rpm                                           |  32 kB  00:00:00    

(12/18): policycoreutils-2.5-29.el7_6.1.x86_64.rpm                                  | 916 kB  00:00:01    

(13/18): selinux-policy-3.13.1-229.el7_6.15.noarch.rpm                              | 484 kB  00:00:00    

(14/18): setools-libs-3.3.8-4.el7.x86_64.rpm                                        | 620 kB  00:00:00    

(15/18): selinux-policy-targeted-3.13.1-229.el7_6.15.noarch.rpm                     | 6.9 MB  00:00:03    

(16/18): audit-libs-python-2.8.4-4.el7.x86_64.rpm                                   |  76 kB  00:00:10    

audit-2.8.4-4.el7.x86_64.rpm   FAILED                                         

http://mirrors.cn99.com/centos/7.6.1810/os/x86_64/Packages/audit-2.8.4-4.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cn99.com; Name or service not known"

Trying other mirror.

(17/18): audit-2.8.4-4.el7.x86_64.rpm                                               | 250 kB  00:00:00    

libselinux-utils-2.5-14.1.el7. FAILED                                          

http://mirror.lzu.edu.cn/centos/7.6.1810/os/x86_64/Packages/libselinux-utils-2.5-14.1.el7.x86_64.rpm: [Errno 14] curl#6 - "Could not resolve host: mirror.lzu.edu.cn; Name or service not known"

Trying other mirror.

(18/18): libselinux-utils-2.5-14.1.el7.x86_64.rpm                                   | 151 kB  00:00:00    

-----------------------------------------------------------------------------------------------------------

Total                                                                      678 kB/s |  11 MB  00:00:16    

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Importing GPG key 0xF4A80EB5:

 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"

 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5

 Package    : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)

 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Updating   : libsepol-2.5-10.el7.x86_64                                                             1/31

  Updating   : libselinux-2.5-14.1.el7.x86_64                                                         2/31

  Updating   : audit-libs-2.8.4-4.el7.x86_64                                                          3/31

  Updating   : libsemanage-2.5-14.el7.x86_64                                                          4/31

  Updating   : libselinux-utils-2.5-14.1.el7.x86_64                                                   5/31

  Updating   : policycoreutils-2.5-29.el7_6.1.x86_64                                                  6/31

  Updating   : selinux-policy-3.13.1-229.el7_6.15.noarch                                              7/31

  Installing : libcgroup-0.41-20.el7.x86_64                                                           8/31

  Updating   : selinux-policy-targeted-3.13.1-229.el7_6.15.noarch                                     9/31

  Installing : libsemanage-python-2.5-14.el7.x86_64                                                  10/31

  Installing : audit-libs-python-2.8.4-4.el7.x86_64                                                  11/31

  Installing : setools-libs-3.3.8-4.el7.x86_64                                                       12/31

  Updating   : libselinux-python-2.5-14.1.el7.x86_64                                                 13/31

  Installing : python-IPy-0.75-6.el7.noarch                                                          14/31

  Installing : checkpolicy-2.5-8.el7.x86_64                                                          15/31

  Installing : policycoreutils-python-2.5-29.el7_6.1.x86_64                                          16/31

  Installing : 2:container-selinux-2.107-1.el7_6.noarch                                              17/31

  Installing : containerd.io-1.2.6-3.3.el7.x86_64                                                    18/31

  Installing : 1:docker-ce-cli-19.03.0-3.el7.x86_64                                                  19/31

  Installing : 3:docker-ce-19.03.0-3.el7.x86_64                                                      20/31

  Updating   : audit-2.8.4-4.el7.x86_64                                                              21/31

  Cleanup    : selinux-policy-targeted-3.13.1-166.el7.noarch                                         22/31

  Cleanup    : selinux-policy-3.13.1-166.el7.noarch                                                  23/31

  Cleanup    : policycoreutils-2.5-17.1.el7.x86_64                                                   24/31

  Cleanup    : libsemanage-2.5-8.el7.x86_64                                                          25/31

  Cleanup    : libselinux-utils-2.5-11.el7.x86_64                                                    26/31

  Cleanup    : libselinux-python-2.5-11.el7.x86_64                                                   27/31

  Cleanup    : libselinux-2.5-11.el7.x86_64                                                          28/31

  Cleanup    : audit-2.7.6-3.el7.x86_64                                                              29/31

  Cleanup    : audit-libs-2.7.6-3.el7.x86_64                                                         30/31

  Cleanup    : libsepol-2.5-6.el7.x86_64                                                             31/31

  Verifying  : libcgroup-0.41-20.el7.x86_64                                                           1/31

  Verifying  : 3:docker-ce-19.03.0-3.el7.x86_64                                                       2/31

  Verifying  : 1:docker-ce-cli-19.03.0-3.el7.x86_64                                                   3/31

  Verifying  : policycoreutils-2.5-29.el7_6.1.x86_64                                                  4/31

  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                           5/31

  Verifying  : audit-libs-2.8.4-4.el7.x86_64                                                          6/31

  Verifying  : audit-2.8.4-4.el7.x86_64                                                               7/31

  Verifying  : python-IPy-0.75-6.el7.noarch                                                           8/31

  Verifying  : selinux-policy-3.13.1-229.el7_6.15.noarch                                              9/31

  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                       10/31

  Verifying  : policycoreutils-python-2.5-29.el7_6.1.x86_64                                          11/31

  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                  12/31

  Verifying  : libsemanage-2.5-14.el7.x86_64                                                         13/31

  Verifying  : libsepol-2.5-10.el7.x86_64                                                            14/31

  Verifying  : containerd.io-1.2.6-3.3.el7.x86_64                                                    15/31

  Verifying  : libselinux-python-2.5-14.1.el7.x86_64                                                 16/31

  Verifying  : selinux-policy-targeted-3.13.1-229.el7_6.15.noarch                                    17/31

  Verifying  : audit-libs-python-2.8.4-4.el7.x86_64                                                  18/31

  Verifying  : libselinux-utils-2.5-14.1.el7.x86_64                                                  19/31

  Verifying  : 2:container-selinux-2.107-1.el7_6.noarch                                              20/31

  Verifying  : libselinux-2.5-14.1.el7.x86_64                                                        21/31

  Verifying  : libselinux-2.5-11.el7.x86_64                                                          22/31

  Verifying  : libsepol-2.5-6.el7.x86_64                                                             23/31

  Verifying  : libselinux-utils-2.5-11.el7.x86_64                                                    24/31

  Verifying  : selinux-policy-3.13.1-166.el7.noarch                                                  25/31

  Verifying  : audit-libs-2.7.6-3.el7.x86_64                                                         26/31

  Verifying  : audit-2.7.6-3.el7.x86_64                                                              27/31

  Verifying  : policycoreutils-2.5-17.1.el7.x86_64                                                   28/31

  Verifying  : libsemanage-2.5-8.el7.x86_64                                                          29/31

  Verifying  : libselinux-python-2.5-11.el7.x86_64                                                   30/31

  Verifying  : selinux-policy-targeted-3.13.1-166.el7.noarch                                         31/31



Installed:

  containerd.io.x86_64 0:1.2.6-3.3.el7                   docker-ce.x86_64 3:19.03.0-3.el7                  

  docker-ce-cli.x86_64 1:19.03.0-3.el7                 



Dependency Installed:

  audit-libs-python.x86_64 0:2.8.4-4.el7            checkpolicy.x86_64 0:2.5-8.el7                        

  container-selinux.noarch 2:2.107-1.el7_6          libcgroup.x86_64 0:0.41-20.el7                        

  libsemanage-python.x86_64 0:2.5-14.el7            policycoreutils-python.x86_64 0:2.5-29.el7_6.1        

  python-IPy.noarch 0:0.75-6.el7                    setools-libs.x86_64 0:3.3.8-4.el7                      



Dependency Updated:

  audit.x86_64 0:2.8.4-4.el7                      audit-libs.x86_64 0:2.8.4-4.el7                        

  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                        

  libsepol.x86_64 0:2.5-10.el7                    policycoreutils.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   



Complete!

2、配置docker镜像仓库地址:

# vi /etc/docker/daemon.json

{

  "registry-mirrors": ["http://hub-mirror.c.163.com"]

}

注:若已启动docker请使用命令“systemctl daemon-reload”重新加载配置或使用命令“systemctl restart docker.service”重启docker

3、启动docker

# systemctl start docker

简单使用docker

1、查看docker版本

# docker --version

Docker version 19.03.0, build aeac9490dc

2、运行hello-world容器检查docker是已经否正确安装

# docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

1b930d010525: Pull complete

Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f

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/

3、查看已下载的docker镜像

# docker image ls

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              fce289e99eb9        7 months ago        1.84kB

4、查看所有正在运行和已退出的容器

# docker container ls -all

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

e66037229cc4        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                       exciting_hugle

回顾和备忘单

## List Docker CLI commands
docker
docker container 
--help

 
## Display Docker version and info
docker 
--version
docker version
docker info

 
## Execute Docker image
docker run hello-world

 
## List Docker images
docker image 
ls

 
## List Docker containers (running, all, all in quiet mode)
docker container 
ls
docker container 
ls
 
--all
docker container 
ls
 
-aq

 

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部