安装docker

准备工作:
lsb_release -a:适用于所有的Linux、包括Rehat、SuSE、Debian等发行版。
1.查看系统内核版本
[root@xiaozhang1999 ~]# uname -r
4.18.0-240.15.1.el8_3.x86_64
2.查看系统版本
[root@xiaozhang1999 ~]# cat /etc/centos-release
CentOS Linux release 8.1.1911 (Core)
[root@xiaozhang1999 ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 8.1.1911 (Core)
Release: 8.1.1911
Codename: Core

一、安装docker

  • 1.卸载旧的版本

sudo yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-engine
  • 2.下载所需的安装包

sudo yum install -y yum-utils

[root@xiaozhang1999 ~]# yum install -y yum-utils
Last metadata expiration check: 2:42:57 ago on Thu 17 Jun 2021 07:38:34 AM CST.
Package yum-utils-4.0.17-5.el8.noarch is already installed.
Dependencies resolved.
=================================================================================================================================================================================================================================================
 Package                                                               Architecture                                        Version                                                     Repository                                           Size
=================================================================================================================================================================================================================================================
Upgrading:
 dnf-plugins-core                                                      noarch                                              4.0.18-4.el8                                                BaseOS                                               69 k
 python3-dnf-plugins-core                                              noarch                                              4.0.18-4.el8                                                BaseOS                                              234 k
 yum-utils                                                             noarch                                              4.0.18-4.el8                                                BaseOS                                               71 k

Transaction Summary
=================================================================================================================================================================================================================================================
Upgrade  3 Packages

Total download size: 375 k
Downloading Packages:
(1/3): yum-utils-4.0.18-4.el8.noarch.rpm                                                                                                                                                                         5.0 MB/s |  71 kB     00:00    
(2/3): dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                                                                                                                                                  4.6 MB/s |  69 kB     00:00    
(3/3): python3-dnf-plugins-core-4.0.18-4.el8.noarch.rpm                                                                                                                                                          6.8 MB/s | 234 kB     00:00    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                             10 MB/s | 375 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                         1/1 
  Upgrading        : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                                                                            1/6 
  Upgrading        : dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                                                                                    2/6 
  Upgrading        : yum-utils-4.0.18-4.el8.noarch                                                                                                                                                                                           3/6 
  Cleanup          : yum-utils-4.0.17-5.el8.noarch                                                                                                                                                                                           4/6 
  Cleanup          : dnf-plugins-core-4.0.17-5.el8.noarch                                                                                                                                                                                    5/6 
  Cleanup          : python3-dnf-plugins-core-4.0.17-5.el8.noarch                                                                                                                                                                            6/6 
  Running scriptlet: python3-dnf-plugins-core-4.0.17-5.el8.noarch                                                                                                                                                                            6/6 
  Verifying        : dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                                                                                    1/6 
  Verifying        : dnf-plugins-core-4.0.17-5.el8.noarch                                                                                                                                                                                    2/6 
  Verifying        : python3-dnf-plugins-core-4.0.18-4.el8.noarch                                                                                                                                                                            3/6 
  Verifying        : python3-dnf-plugins-core-4.0.17-5.el8.noarch                                                                                                                                                                            4/6 
  Verifying        : yum-utils-4.0.18-4.el8.noarch                                                                                                                                                                                           5/6 
  Verifying        : yum-utils-4.0.17-5.el8.noarch                                                                                                                                                                                           6/6 
Installed products updated.

Upgraded:
  dnf-plugins-core-4.0.18-4.el8.noarch                                           python3-dnf-plugins-core-4.0.18-4.el8.noarch                                           yum-utils-4.0.18-4.el8.noarch                                          

Complete!


  • 3.设置镜像的仓库

默认是国外的DockerHub,速度十分的慢
yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
国内的阿里云镜像地址下载镜像速度十分快
yum-config-manager
--add-repo
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@xiaozhang1999 ~]# sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

//更新yum索引
yum makecache fast

CentOS8版本没有fast参数去掉即可

[root@xiaozhang1999 ~]# yum makecache 
CentOS-8 - AppStream                                                                                                                                                                                             1.1 MB/s | 4.3 kB     00:00    
CentOS-8 - Base                                                                                                                                                                                                  903 kB/s | 3.9 kB     00:00    
CentOS-8 - Extras                                                                                                                                                                                                212 kB/s | 1.5 kB     00:00    
Extra Packages for Enterprise Linux 8 - x86_64                                                                                                                                                                   703 kB/s | 4.7 kB     00:00    
Docker CE Stable - x86_64                                                                                                                                                                                         57 kB/s | 3.5 kB     00:00    
MySQL Connectors Community                                                                                                                                                                                       8.9 kB/s | 2.6 kB     00:00    
MySQL Tools Community                                                                                                                                                                                            9.5 kB/s | 2.6 kB     00:00    
MySQL 5.7 Community Server                                                                                                                                                                                       9.5 kB/s | 2.6 kB     00:00    
Metadata cache created.
  • 4.安装最新的docker相关的 docker-ce 社区版 ee企业版(推荐使用ce)、按一次Y确定

yum install docker-ce docker-ce-cli containerd.io
//指定docker版本安装
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

[root@xiaozhang1999 ~]# yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:01:56 ago on Thu 17 Jun 2021 10:53:32 AM CST.
Package docker-ce-3:20.10.5-3.el8.x86_64 is already installed.
Package docker-ce-cli-1:20.10.5-3.el8.x86_64 is already installed.
Package containerd.io-1.4.4-3.1.el8.x86_64 is already installed.
Dependencies resolved.
=================================================================================================================================================================================================================================================
 Package                                                       Architecture                                      Version                                                       Repository                                                   Size
=================================================================================================================================================================================================================================================
Upgrading:
 containerd.io                                                 x86_64                                            1.4.6-3.1.el8                                                 docker-ce-stable                                             34 M
 docker-ce                                                     x86_64                                            3:20.10.7-3.el8                                               docker-ce-stable                                             27 M
 docker-ce-cli                                                 x86_64                                            1:20.10.7-3.el8                                               docker-ce-stable                                             33 M
Installing dependencies:
 docker-scan-plugin                                            x86_64                                            0.8.0-3.el8                                                   docker-ce-stable                                            4.2 M

Transaction Summary
=================================================================================================================================================================================================================================================
Install  1 Package
Upgrade  3 Packages

Total download size: 97 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): docker-scan-plugin-0.8.0-3.el8.x86_64.rpm                                                                                                                                                                 1.3 MB/s | 4.2 MB     00:03    
(2/4): docker-ce-20.10.7-3.el8.x86_64.rpm                                                                                                                                                                        1.3 MB/s |  27 MB     00:20    
(3/4): containerd.io-1.4.6-3.1.el8.x86_64.rpm                                                                                                                                                                    1.3 MB/s |  34 MB     00:26    
(4/4): docker-ce-cli-20.10.7-3.el8.x86_64.rpm                                                                                                                                                                    1.3 MB/s |  33 MB     00:24    
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                            3.5 MB/s |  97 MB     00:28     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                         1/1 
  Running scriptlet: docker-ce-cli-1:20.10.7-3.el8.x86_64                                                                                                                                                                                    1/1 
  Upgrading        : docker-ce-cli-1:20.10.7-3.el8.x86_64                                                                                                                                                                                    1/7 
  Running scriptlet: docker-ce-cli-1:20.10.7-3.el8.x86_64                                                                                                                                                                                    1/7 
  Installing       : docker-scan-plugin-0.8.0-3.el8.x86_64                                                                                                                                                                                   2/7 
  Running scriptlet: docker-scan-plugin-0.8.0-3.el8.x86_64                                                                                                                                                                                   2/7 
  Upgrading        : containerd.io-1.4.6-3.1.el8.x86_64                                                                                                                                                                                      3/7 
  Running scriptlet: containerd.io-1.4.6-3.1.el8.x86_64                                                                                                                                                                                      3/7 
  Upgrading        : docker-ce-3:20.10.7-3.el8.x86_64                                                                                                                                                                                        4/7 
  Running scriptlet: docker-ce-3:20.10.7-3.el8.x86_64                                                                                                                                                                                        4/7 
  Running scriptlet: docker-ce-3:20.10.5-3.el8.x86_64                                                                                                                                                                                        5/7 
  Cleanup          : docker-ce-3:20.10.5-3.el8.x86_64                                                                                                                                                                                        5/7 
  Running scriptlet: docker-ce-3:20.10.5-3.el8.x86_64                                                                                                                                                                                        5/7 
  Running scriptlet: containerd.io-1.4.4-3.1.el8.x86_64                                                                                                                                                                                      6/7 
  Cleanup          : containerd.io-1.4.4-3.1.el8.x86_64                                                                                                                                                                                      6/7 
  Running scriptlet: containerd.io-1.4.4-3.1.el8.x86_64                                                                                                                                                                                      6/7 
  Cleanup          : docker-ce-cli-1:20.10.5-3.el8.x86_64                                                                                                                                                                                    7/7 
  Running scriptlet: docker-ce-cli-1:20.10.5-3.el8.x86_64                                                                                                                                                                                    7/7 
  Verifying        : docker-scan-plugin-0.8.0-3.el8.x86_64                                                                                                                                                                                   1/7 
  Verifying        : containerd.io-1.4.6-3.1.el8.x86_64                                                                                                                                                                                      2/7 
  Verifying        : containerd.io-1.4.4-3.1.el8.x86_64                                                                                                                                                                                      3/7 
  Verifying        : docker-ce-3:20.10.7-3.el8.x86_64                                                                                                                                                                                        4/7 
  Verifying        : docker-ce-3:20.10.5-3.el8.x86_64                                                                                                                                                                                        5/7 
  Verifying        : docker-ce-cli-1:20.10.7-3.el8.x86_64                                                                                                                                                                                    6/7 
  Verifying        : docker-ce-cli-1:20.10.5-3.el8.x86_64                                                                                                                                                                                    7/7 
Installed products updated.

Upgraded:
  containerd.io-1.4.6-3.1.el8.x86_64                                              docker-ce-3:20.10.7-3.el8.x86_64                                              docker-ce-cli-1:20.10.7-3.el8.x86_64                                             

Installed:
  docker-scan-plugin-0.8.0-3.el8.x86_64                                                                                                                                                                                                          

Complete!
  • 5.启动docker

systemctl start docker
//检测docker是否安装成功
docker version

[root@xiaozhang1999 ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:24 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:48 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
  • 6.启动镜像测试

docker run hello-world
1)Unable to find image ‘hello-world:latest‘ locally:先从本地仓库找、找不到hello world镜像
2)b8dfde127a29: Pull complete:从远程仓库Docker hub去拉Hello world镜像
3)签名信息下载成功:Digest:sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
Status: Downloaded newer image for hello-world:latest
4)Hello from Docker!:安装镜像成功

[root@xiaozhang1999 ~]# docker run hello-world
Unable to find image ‘hello-world:latest‘ locally

latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:9f6ad537c5132bcce57f7a0a20e317228d382c3cd61edae14650eec68b2b345c
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/

  • 7.查看hello world的镜像docker images

docker images

[root@xiaozhang1999 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   3 months ago   13.3kB
nginx         latest    f6d0b4767a6c   5 months ago   133MB
  • 8.卸载Docker

yum remove docker-ce docker-ce-cli containerd.io
/var/lib/docker #docker的默认工作路径
rm -rf /var/lib/docker #卸载资源
rm -rf /var/lib/containerd #删除路径

二、配置阿里云镜像加速

  • 1.登录阿里云找到"容器镜像服务"下的镜像加速器

安装docker

安装docker

上一篇:RabbitMQ 高阶用法 之 x-expire 过期时间设置


下一篇:WIN7 + IIS7 Service Unavailable HTTP Error 503. The service is unavailable.