查看系统版本和系统内核信息

[root@Tseng-HW ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 8.2.2004 (Core) 
Release:	8.2.2004
Codename:	Core
[root@Tseng-HW ~]# uname -r
4.18.0-240.10.1.el8_3.x86_64
[root@Tseng-HW ~]#

1. 下载docker-ce的repo

[root@Tseng-HW ~]# curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo

2. 安装依赖

[root@Tseng-HW ~]# yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm

3. 安装docker-ce

[root@Tseng-HW ~]# dnf -y  install docker-ce  docker-ce-cli --nobest

4.启动 docker

[root@Tseng-HW ~]# systemctl start docker

5.查看 docker 版本信息

[root@Tseng-HW ~]# docker -v
Docker version 20.10.11, build dea9396

6.设置开机自动启动

[root@Tseng-HW ~]# systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
[root@Tseng-HW ~]#

7、Alibaba Cloud Linux 3 安装社区版Docker(docker-ce)。

  1. 运行以下命令,添加docker-ce的dnf源。
    dnf config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  2. 运行以下命令,安装Alibaba Cloud Linux 3专用的dnf源兼容插件。
    dnf -y install dnf-plugin-releasever-adapter --repo alinux3-plus

    如果您不使用Alibaba Cloud Linux 3专用的dnf源兼容插件,将无法正常安装docker-ce。

  3. 运行以下命令,安装docker-ce。
    dnf -y install docker-ce --nobest
    如果执行命令,出现类似下图的报错信息,您需要注释/etc/yum.repos.d下的CentOS源,注释后重新安装docker-ce。

  4. 运行以下命令,查看docker-ce是否成功安装。
    dnf list docker-ce

    回显信息如下图所示,表示docker-ce成功安装。

  5. 运行以下命令,启动Docker服务。
    systemctl start docker
  6. 运行以下命令,查看Docker服务的运行状态

新服务器执行参考:

[root@iZbp19kg4d65mawlshvahzZ ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           29Gi       218Mi        28Gi       1.0Mi       645Mi        29Gi
Swap:            0B          0B          0B
[root@iZbp19kg4d65mawlshvahzZ ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch
Distributor ID:	AlibabaCloud
Description:	Alibaba Cloud Linux release 3 (Soaring Falcon) 
Release:	3
Codename:	SoaringFalcon
[root@iZbp19kg4d65mawlshvahzZ ~]# dnf config-manager --add-repo=https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@iZbp19kg4d65mawlshvahzZ ~]# dnf -y install dnf-plugin-releasever-adapter --repo alinux3-plus
Last metadata expiration check: 0:12:34 ago on Mon 08 May 2023 01:40:42 PM CST.
Package dnf-plugin-releasever-adapter-1.0-2.al8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@iZbp19kg4d65mawlshvahzZ ~]# dnf -y install docker-ce --nobest
Docker CE Stable - x86_64                                                                                                                                                                 301 kB/s |  42 kB     00:00    
Dependencies resolved.
==========================================================================================================================================================================================================================
 Package                                                         Architecture                              Version                                              Repository                                           Size
==========================================================================================================================================================================================================================
Installing:
 docker-ce                                                       x86_64                                    3:23.0.5-1.el8                                       docker-ce-stable                                     23 M
Installing dependencies:
 checkpolicy                                                     x86_64                                    2.9-1.2.al8                                          alinux3-os                                          348 k
 container-selinux                                               noarch                                    2:2.189.0-1.al8                                      alinux3-updates                                      59 k
 containerd.io                                                   x86_64                                    1.6.21-3.1.el8                                       docker-ce-stable                                     34 M
 docker-ce-cli                                                   x86_64                                    1:23.0.5-1.el8                                       docker-ce-stable                                    7.1 M
 docker-ce-rootless-extras                                       x86_64                                    23.0.5-1.el8                                         docker-ce-stable                                    4.8 M
 fuse-overlayfs                                                  x86_64                                    1.9-1.al8                                            alinux3-updates                                      73 k
 fuse3                                                           x86_64                                    3.3.0-15.al8                                         alinux3-updates                                      54 k
 fuse3-libs                                                      x86_64                                    3.3.0-15.al8                                         alinux3-updates                                      97 k
 libcgroup                                                       x86_64                                    0.41-19.2.al8                                        alinux3-os                                           70 k
 libslirp                                                        x86_64                                    4.4.0-1.al8                                          alinux3-updates                                      71 k
 policycoreutils-python-utils                                    noarch                                    2.9-20.al8                                           alinux3-updates                                     253 k
 python3-audit                                                   x86_64                                    3.0.7-2.al8.2                                        alinux3-updates                                      86 k
 python3-libsemanage                                             x86_64                                    2.9-9.al8                                            alinux3-updates                                     124 k
 python3-policycoreutils                                         noarch                                    2.9-20.al8                                           alinux3-updates                                     2.2 M
 python3-setools                                                 x86_64                                    4.3.0-3.al8                                          alinux3-updates                                     651 k
 slirp4netns                                                     x86_64                                    1.2.0-2.al8                                          alinux3-updates                                      54 k
Installing weak dependencies:
 docker-buildx-plugin                                            x86_64                                    0.10.4-1.el8                                         docker-ce-stable                                     12 M
 docker-compose-plugin                                           x86_64                                    2.17.3-1.el8                                         docker-ce-stable                                     12 M

Transaction Summary
==========================================================================================================================================================================================================================
Install  19 Packages

Total download size: 97 M
Installed size: 367 M
Downloading Packages:
(1/19): container-selinux-2.189.0-1.al8.noarch.rpm                                                                                                                                        3.1 MB/s |  59 kB     00:00    
(2/19): libcgroup-0.41-19.2.al8.x86_64.rpm                                                                                                                                                1.9 MB/s |  70 kB     00:00    
(3/19): checkpolicy-2.9-1.2.al8.x86_64.rpm                                                                                                                                                7.4 MB/s | 348 kB     00:00    
(4/19): fuse-overlayfs-1.9-1.al8.x86_64.rpm                                                                                                                                               2.2 MB/s |  73 kB     00:00    
(5/19): fuse3-3.3.0-15.al8.x86_64.rpm                                                                                                                                                     2.2 MB/s |  54 kB     00:00    
(6/19): libslirp-4.4.0-1.al8.x86_64.rpm                                                                                                                                                   2.7 MB/s |  71 kB     00:00    
(7/19): fuse3-libs-3.3.0-15.al8.x86_64.rpm                                                                                                                                                2.5 MB/s |  97 kB     00:00    
(8/19): policycoreutils-python-utils-2.9-20.al8.noarch.rpm                                                                                                                                9.0 MB/s | 253 kB     00:00    
(9/19): python3-libsemanage-2.9-9.al8.x86_64.rpm                                                                                                                                           10 MB/s | 124 kB     00:00    
(10/19): python3-audit-3.0.7-2.al8.2.x86_64.rpm                                                                                                                                           3.6 MB/s |  86 kB     00:00    
(11/19): python3-setools-4.3.0-3.al8.x86_64.rpm                                                                                                                                            16 MB/s | 651 kB     00:00    
(12/19): slirp4netns-1.2.0-2.al8.x86_64.rpm                                                                                                                                               1.4 MB/s |  54 kB     00:00    
(13/19): python3-policycoreutils-2.9-20.al8.noarch.rpm                                                                                                                                     20 MB/s | 2.2 MB     00:00    
(14/19): docker-buildx-plugin-0.10.4-1.el8.x86_64.rpm                                                                                                                                     5.4 MB/s |  12 MB     00:02    
(15/19): docker-ce-cli-23.0.5-1.el8.x86_64.rpm                                                                                                                                            2.9 MB/s | 7.1 MB     00:02    
(16/19): docker-ce-23.0.5-1.el8.x86_64.rpm                                                                                                                                                4.8 MB/s |  23 MB     00:04    
(17/19): docker-ce-rootless-extras-23.0.5-1.el8.x86_64.rpm                                                                                                                                3.1 MB/s | 4.8 MB     00:01    
(18/19): docker-compose-plugin-2.17.3-1.el8.x86_64.rpm                                                                                                                                    6.3 MB/s |  12 MB     00:01    
(19/19): containerd.io-1.6.21-3.1.el8.x86_64.rpm                                                                                                                                          4.9 MB/s |  34 MB     00:06    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                      14 MB/s |  97 MB     00:07     
Docker CE Stable - x86_64                                                                                                                                                                  27 kB/s | 1.6 kB     00:00    
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://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                  1/1 
  Installing       : docker-compose-plugin-2.17.3-1.el8.x86_64                                                                                                                                                       1/19 
  Running scriptlet: docker-compose-plugin-2.17.3-1.el8.x86_64                                                                                                                                                       1/19 
  Installing       : fuse3-libs-3.3.0-15.al8.x86_64                                                                                                                                                                  2/19 
  Running scriptlet: fuse3-libs-3.3.0-15.al8.x86_64                                                                                                                                                                  2/19 
  Installing       : fuse3-3.3.0-15.al8.x86_64                                                                                                                                                                       3/19 
  Installing       : fuse-overlayfs-1.9-1.al8.x86_64                                                                                                                                                                 4/19 
  Running scriptlet: fuse-overlayfs-1.9-1.al8.x86_64                                                                                                                                                                 4/19 
  Installing       : docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                                                                        5/19 
  Running scriptlet: docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                                                                        5/19 
  Installing       : docker-ce-cli-1:23.0.5-1.el8.x86_64                                                                                                                                                             6/19 
  Running scriptlet: docker-ce-cli-1:23.0.5-1.el8.x86_64                                                                                                                                                             6/19 
  Installing       : python3-setools-4.3.0-3.al8.x86_64                                                                                                                                                              7/19 
  Installing       : python3-libsemanage-2.9-9.al8.x86_64                                                                                                                                                            8/19 
  Installing       : python3-audit-3.0.7-2.al8.2.x86_64                                                                                                                                                              9/19 
  Installing       : libslirp-4.4.0-1.al8.x86_64                                                                                                                                                                    10/19 
  Installing       : slirp4netns-1.2.0-2.al8.x86_64                                                                                                                                                                 11/19 
  Running scriptlet: libcgroup-0.41-19.2.al8.x86_64                                                                                                                                                                 12/19 
  Installing       : libcgroup-0.41-19.2.al8.x86_64                                                                                                                                                                 12/19 
  Running scriptlet: libcgroup-0.41-19.2.al8.x86_64                                                                                                                                                                 12/19 
  Installing       : checkpolicy-2.9-1.2.al8.x86_64                                                                                                                                                                 13/19 
  Installing       : python3-policycoreutils-2.9-20.al8.noarch                                                                                                                                                      14/19 
  Installing       : policycoreutils-python-utils-2.9-20.al8.noarch                                                                                                                                                 15/19 
  Running scriptlet: container-selinux-2:2.189.0-1.al8.noarch                                                                                                                                                       16/19 
  Installing       : container-selinux-2:2.189.0-1.al8.noarch                                                                                                                                                       16/19 
  Running scriptlet: container-selinux-2:2.189.0-1.al8.noarch                                                                                                                                                       16/19 



  Installing       : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                                            17/19 
  Running scriptlet: containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                                            17/19 
  Installing       : docker-ce-rootless-extras-23.0.5-1.el8.x86_64                                                                                                                                                  18/19 
  Running scriptlet: docker-ce-rootless-extras-23.0.5-1.el8.x86_64                                                                                                                                                  18/19 
  Installing       : docker-ce-3:23.0.5-1.el8.x86_64                                                                                                                                                                19/19 
  Running scriptlet: docker-ce-3:23.0.5-1.el8.x86_64                                                                                                                                                                19/19 
  Running scriptlet: container-selinux-2:2.189.0-1.al8.noarch                                                                                                                                                       19/19 
  Running scriptlet: docker-ce-3:23.0.5-1.el8.x86_64                                                                                                                                                                19/19 
  Verifying        : checkpolicy-2.9-1.2.al8.x86_64                                                                                                                                                                  1/19 
  Verifying        : libcgroup-0.41-19.2.al8.x86_64                                                                                                                                                                  2/19 
  Verifying        : container-selinux-2:2.189.0-1.al8.noarch                                                                                                                                                        3/19 
  Verifying        : fuse-overlayfs-1.9-1.al8.x86_64                                                                                                                                                                 4/19 
  Verifying        : fuse3-3.3.0-15.al8.x86_64                                                                                                                                                                       5/19 
  Verifying        : fuse3-libs-3.3.0-15.al8.x86_64                                                                                                                                                                  6/19 
  Verifying        : libslirp-4.4.0-1.al8.x86_64                                                                                                                                                                     7/19 
  Verifying        : policycoreutils-python-utils-2.9-20.al8.noarch                                                                                                                                                  8/19 
  Verifying        : python3-audit-3.0.7-2.al8.2.x86_64                                                                                                                                                              9/19 
  Verifying        : python3-libsemanage-2.9-9.al8.x86_64                                                                                                                                                           10/19 
  Verifying        : python3-policycoreutils-2.9-20.al8.noarch                                                                                                                                                      11/19 
  Verifying        : python3-setools-4.3.0-3.al8.x86_64                                                                                                                                                             12/19 
  Verifying        : slirp4netns-1.2.0-2.al8.x86_64                                                                                                                                                                 13/19 
  Verifying        : containerd.io-1.6.21-3.1.el8.x86_64                                                                                                                                                            14/19 
  Verifying        : docker-buildx-plugin-0.10.4-1.el8.x86_64                                                                                                                                                       15/19 
  Verifying        : docker-ce-3:23.0.5-1.el8.x86_64                                                                                                                                                                16/19 
  Verifying        : docker-ce-cli-1:23.0.5-1.el8.x86_64                                                                                                                                                            17/19 
  Verifying        : docker-ce-rootless-extras-23.0.5-1.el8.x86_64                                                                                                                                                  18/19 
  Verifying        : docker-compose-plugin-2.17.3-1.el8.x86_64                                                                                                                                                      19/19 

Installed:
  checkpolicy-2.9-1.2.al8.x86_64         container-selinux-2:2.189.0-1.al8.noarch        containerd.io-1.6.21-3.1.el8.x86_64         docker-buildx-plugin-0.10.4-1.el8.x86_64         docker-ce-3:23.0.5-1.el8.x86_64     
  docker-ce-cli-1:23.0.5-1.el8.x86_64    docker-ce-rootless-extras-23.0.5-1.el8.x86_64   docker-compose-plugin-2.17.3-1.el8.x86_64   fuse-overlayfs-1.9-1.al8.x86_64                  fuse3-3.3.0-15.al8.x86_64           
  fuse3-libs-3.3.0-15.al8.x86_64         libcgroup-0.41-19.2.al8.x86_64                  libslirp-4.4.0-1.al8.x86_64                 policycoreutils-python-utils-2.9-20.al8.noarch   python3-audit-3.0.7-2.al8.2.x86_64  
  python3-libsemanage-2.9-9.al8.x86_64   python3-policycoreutils-2.9-20.al8.noarch       python3-setools-4.3.0-3.al8.x86_64          slirp4netns-1.2.0-2.al8.x86_64                  

Complete!
[root@iZbp19kg4d65mawlshvahzZ ~]# 
[root@iZbp19kg4d65mawlshvahzZ ~]# 
[root@iZbp19kg4d65mawlshvahzZ ~]# 
[root@iZbp19kg4d65mawlshvahzZ ~]# dnf list docker-ce
Last metadata expiration check: 0:00:13 ago on Mon 08 May 2023 01:54:47 PM CST.
Installed Packages
docker-ce.x86_64                                                                                     3:23.0.5-1.el8                                                                                      @docker-ce-stable
[root@iZbp19kg4d65mawlshvahzZ ~]# systemctl start docker
[root@iZbp19kg4d65mawlshvahzZ ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2023-05-08 13:55:27 CST; 7s ago
     Docs: https://docs.docker.com
 Main PID: 7253 (dockerd)
    Tasks: 12
   Memory: 29.3M
   CGroup: /system.slice/docker.service
           └─7253 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

May 08 13:55:26 iZbp19kg4d65mawlshvahzZ systemd[1]: Starting Docker Application Container Engine...
May 08 13:55:26 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:26.784482286+08:00" level=info msg="Starting up"
May 08 13:55:26 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:26.821512467+08:00" level=info msg="Loading containers: start."
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:27.132312686+08:00" level=info msg="Loading containers: done."
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:27.147869717+08:00" level=warning msg="Not using native diff for overlay2, this may cause degraded performance for building images: kernel >
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:27.148058427+08:00" level=info msg="Docker daemon" commit=94d3ad6 graphdriver=overlay2 version=23.0.5
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:27.148147446+08:00" level=info msg="Daemon has completed initialization"
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ systemd[1]: Started Docker Application Container Engine.
May 08 13:55:27 iZbp19kg4d65mawlshvahzZ dockerd[7253]: time="2023-05-08T13:55:27.180481680+08:00" level=info msg="API listen on /run/docker.sock"
[root@iZbp19kg4d65mawlshvahzZ ~]# systemctl enable docker 
[root@iZbp19kg4d65mawlshvahzZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@iZbp19kg4d65mawlshvahzZ ~]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
[root@iZbp19kg4d65mawlshvahzZ ~]#
  1. systemctl status docker
    回显信息如下图所示,表示Docker服务处于运行中的状态。

    说明 如果您需要查看Docker的版本,请运行docker -v命令。

使用Docker Docker有以下基本用法: 管理Docker守护进程。

systemctl start docker     #运行Docker守护进程
systemctl stop docker      #停止Docker守护进程
systemctl restart docker   #重启Docker守护进程
systemctl enable docker    #设置Docker开机自启动
systemctl status docker    #查看Docker的运行状态

说明 通过yum源的方式安装的Docker(podman-docker)没有守护进程(systemd),因此不支持systemctl命令的相关操作。

7、设置加速镜像(阿里云镜像) 

针对Docker客户端版本大于 1.10.0 的用户

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://8dp7kg6k.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐