docker教程02(docker的安装)

1卸载旧版本的docker

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

如果你没有安装过docker,执行后结果如下

[root@docerk01 opt]# sudo yum remove docker \
>                   docker-client \
>                   docker-client-latest \
>                   docker-common \
>                   docker-latest \
>                   docker-latest-logrotate \
>                   docker-logrotate \
>                   docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal

2设置yum仓库

执行命令

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

运行截图:

[root@docker01 opt]#  sudo yum install -y yum-utils
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
base                                                     | 3.6 kB     00:00     
extras                                                   | 2.9 kB     00:00     
updates                                                  | 2.9 kB     00:00     
(1/2): extras/7/x86_64/primary_db                          | 205 kB   00:00     
(2/2): updates/7/x86_64/primary_db                         | 3.0 MB   00:01     
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-54.el7_8.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7.4 will be installed
--> Processing Dependency: libxml2 = 2.9.1-6.el7.4 for package: libxml2-python-2.9.1-6.el7.4.x86_64
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package libxml2.x86_64 0:2.9.1-6.el7_2.3 will be updated
---> Package libxml2.x86_64 0:2.9.1-6.el7.4 will be an update
---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch         Version                  Repository     Size
================================================================================
Installing:
 yum-utils            noarch       1.1.31-54.el7_8          updates       122 k
Installing for dependencies:
 libxml2-python       x86_64       2.9.1-6.el7.4            base          247 k
 python-chardet       noarch       2.2.1-3.el7              base          227 k
 python-kitchen       noarch       1.1.1-5.el7              base          267 k
Updating for dependencies:
 libxml2              x86_64       2.9.1-6.el7.4            base          668 k

Transaction Summary
================================================================================
Install  1 Package  (+3 Dependent packages)
Upgrade             ( 1 Dependent package)

Total download size: 1.5 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/5): libxml2-python-2.9.1-6.el7.4.x86_64.rpm             | 247 kB   00:00     
(2/5): libxml2-2.9.1-6.el7.4.x86_64.rpm                    | 668 kB   00:00     
(3/5): python-chardet-2.2.1-3.el7.noarch.rpm               | 227 kB   00:00     
(4/5): yum-utils-1.1.31-54.el7_8.noarch.rpm                | 122 kB   00:00     
(5/5): python-kitchen-1.1.1-5.el7.noarch.rpm               | 267 kB   00:00     
--------------------------------------------------------------------------------
Total                                              2.6 MB/s | 1.5 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libxml2-2.9.1-6.el7.4.x86_64                                 1/6 
  Installing : libxml2-python-2.9.1-6.el7.4.x86_64                          2/6 
  Installing : python-chardet-2.2.1-3.el7.noarch                            3/6 
  Installing : python-kitchen-1.1.1-5.el7.noarch                            4/6 
  Installing : yum-utils-1.1.31-54.el7_8.noarch                             5/6 
  Cleanup    : libxml2-2.9.1-6.el7_2.3.x86_64                               6/6 
  Verifying  : python-chardet-2.2.1-3.el7.noarch                            1/6 
  Verifying  : python-kitchen-1.1.1-5.el7.noarch                            2/6 
  Verifying  : libxml2-python-2.9.1-6.el7.4.x86_64                          3/6 
  Verifying  : libxml2-2.9.1-6.el7.4.x86_64                                 4/6 
  Verifying  : yum-utils-1.1.31-54.el7_8.noarch                             5/6 
  Verifying  : libxml2-2.9.1-6.el7_2.3.x86_64                               6/6 

Installed:
  yum-utils.noarch 0:1.1.31-54.el7_8                                            

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7.4   python-chardet.noarch 0:2.2.1-3.el7  
  python-kitchen.noarch 0:1.1.1-5.el7    

Dependency Updated:
  libxml2.x86_64 0:2.9.1-6.el7.4                                                

Complete!

[root@docker opt]# 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

3安装docker引擎

运行命令:

sudo yum install docker-ce docker-ce-cli containerd.io

运行截图

[root@docer opt]# sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
docker-ce-stable                                         | 3.5 kB     00:00     
(1/2): docker-ce-stable/x86_64/updateinfo                  |   55 B   00:00     
(2/2): docker-ce-stable/x86_64/primary_db                  |  45 kB   00:00     
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.2.13-3.2.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.2.13-3.2.el7.x86_64
---> Package docker-ce.x86_64 3:19.03.12-3.el7 will be installed
--> Processing Dependency: libcgroup for package: 3:docker-ce-19.03.12-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:19.03.12-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.119.2-1.911c772.el7_8.noarch
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: policycoreutils = 2.5-34.el7 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package policycoreutils.x86_64 0:2.5-33.el7 will be updated
---> Package policycoreutils.x86_64 0:2.5-34.el7 will be an update
---> 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
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch   Version                   Repository        Size
================================================================================
Installing:
 containerd.io          x86_64 1.2.13-3.2.el7            docker-ce-stable  25 M
 docker-ce              x86_64 3:19.03.12-3.el7          docker-ce-stable  24 M
 docker-ce-cli          x86_64 1:19.03.12-3.el7          docker-ce-stable  38 M
Installing for dependencies:
 audit-libs-python      x86_64 2.8.5-4.el7               base              76 k
 checkpolicy            x86_64 2.5-8.el7                 base             295 k
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 libcgroup              x86_64 0.41-21.el7               base              66 k
 libsemanage-python     x86_64 2.5-14.el7                base             113 k
 policycoreutils-python x86_64 2.5-34.el7                base             457 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:
 policycoreutils        x86_64 2.5-34.el7                base             917 k

Transaction Summary
================================================================================
Install  3 Packages (+8 Dependent packages)
Upgrade             ( 1 Dependent package)

Total download size: 90 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/12): container-selinux-2.119.2-1.911c772.el7_8.noarch.r |  40 kB   00:00     
(2/12): audit-libs-python-2.8.5-4.el7.x86_64.rpm           |  76 kB   00:00     
(3/12): checkpolicy-2.5-8.el7.x86_64.rpm                   | 295 kB   00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.12-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-19.03.12-3.el7.x86_64.rpm is not installed
(4/12): docker-ce-19.03.12-3.el7.x86_64.rpm                |  24 MB   00:08     
(5/12): libcgroup-0.41-21.el7.x86_64.rpm                   |  66 kB   00:00     
(6/12): libsemanage-python-2.5-14.el7.x86_64.rpm           | 113 kB   00:00     
(7/12): policycoreutils-python-2.5-34.el7.x86_64.rpm       | 457 kB   00:00     
(8/12): python-IPy-0.75-6.el7.noarch.rpm                   |  32 kB   00:00     
(9/12): setools-libs-3.3.8-4.el7.x86_64.rpm                | 620 kB   00:00     
(10/12): containerd.io-1.2.13-3.2.el7.x86_64.rpm           |  25 MB   00:09     
(11/12): policycoreutils-2.5-34.el7.x86_64.rpm             | 917 kB   00:01     
(12/12): docker-ce-cli-19.03.12-3.el7.x86_64.rpm           |  38 MB   00:07     
--------------------------------------------------------------------------------
Total                                              5.5 MB/s |  90 MB  00:16     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libcgroup-0.41-21.el7.x86_64                                1/13 
  Updating   : policycoreutils-2.5-34.el7.x86_64                           2/13 
  Installing : setools-libs-3.3.8-4.el7.x86_64                             3/13 
  Installing : 1:docker-ce-cli-19.03.12-3.el7.x86_64                       4/13 
  Installing : python-IPy-0.75-6.el7.noarch                                5/13 
  Installing : libsemanage-python-2.5-14.el7.x86_64                        6/13 
  Installing : audit-libs-python-2.8.5-4.el7.x86_64                        7/13 
  Installing : checkpolicy-2.5-8.el7.x86_64                                8/13 
  Installing : policycoreutils-python-2.5-34.el7.x86_64                    9/13 
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch         10/13 
setsebool:  SELinux is disabled.
  Installing : containerd.io-1.2.13-3.2.el7.x86_64                        11/13 
  Installing : 3:docker-ce-19.03.12-3.el7.x86_64                          12/13 
  Cleanup    : policycoreutils-2.5-33.el7.x86_64                          13/13 
  Verifying  : checkpolicy-2.5-8.el7.x86_64                                1/13 
  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                        2/13 
  Verifying  : policycoreutils-2.5-34.el7.x86_64                           3/13 
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                        4/13 
  Verifying  : containerd.io-1.2.13-3.2.el7.x86_64                         5/13 
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch          6/13 
  Verifying  : python-IPy-0.75-6.el7.noarch                                7/13 
  Verifying  : policycoreutils-python-2.5-34.el7.x86_64                    8/13 
  Verifying  : 1:docker-ce-cli-19.03.12-3.el7.x86_64                       9/13 
  Verifying  : 3:docker-ce-19.03.12-3.el7.x86_64                          10/13 
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                            11/13 
  Verifying  : libcgroup-0.41-21.el7.x86_64                               12/13 
  Verifying  : policycoreutils-2.5-33.el7.x86_64                          13/13 

Installed:
  containerd.io.x86_64 0:1.2.13-3.2.el7    docker-ce.x86_64 3:19.03.12-3.el7   
  docker-ce-cli.x86_64 1:19.03.12-3.el7   

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7                                        
  checkpolicy.x86_64 0:2.5-8.el7                                                
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8                            
  libcgroup.x86_64 0:0.41-21.el7                                                
  libsemanage-python.x86_64 0:2.5-14.el7                                        
  policycoreutils-python.x86_64 0:2.5-34.el7                                    
  python-IPy.noarch 0:0.75-6.el7                                                
  setools-libs.x86_64 0:3.3.8-4.el7                                             

Dependency Updated:
  policycoreutils.x86_64 0:2.5-34.el7                                           

Complete!
[root@dg002 opt]# sudo systemctl start docker^C
[root@dg002 opt]# sudo yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
Package 3:docker-ce-19.03.12-3.el7.x86_64 already installed and latest version
Package 1:docker-ce-cli-19.03.12-3.el7.x86_64 already installed and latest version
Package containerd.io-1.2.13-3.2.el7.x86_64 already installed and latest version
Nothing to do

4 修改镜像源

vi /etc/docker/daemon.json
{"registry-mirrors": ["http://hub-mirror.c.163.com"]}

4启动docker

sudo systemctl start docker

运行docker的hello world

[root@docker root]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:49a1c8800c94df04e9658809b006fd8a686cab8028d33cfba2cc049724254202
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,服务器)