1.卸载旧版本

较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项,否则容易造成冲突。

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

2.更换阿里yum源

按官方文档的说明进行了yum源更换,不进行更换接下来的安装可能会出现报错。

阿里云安装文档:
https://developer.aliyun.com/mirror/centos

3.安装 Docker Engine-Community

使用 Docker 仓库进行安装
在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker。

设置仓库

安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

使用以下命令来设置稳定的仓库,以阿里云源地址为例:

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

4.安装 Docker Engine-Community

安装最新版本的 Docker Engine-Community 和 containerd

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

此时会安装失败,报错如下:

package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the provide

问题分析:centos8默认使用podman代替docker,所以需要安装containerd.io

解决方法:安装containerd.io即可

yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm

此时可能会出现报错

package podman-3.0.1-7.module_el8.4.0 830 8027e1c4.x86_64 requires runc >= 1

问题分析:podman包冲突
解决方法:解决冲突

yum erase podman buildah

最后再进行第四步安装即可

5.启动 Docker。

$ sudo systemctl start docker

6.通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 。

$ sudo docker run hello-world

若输出下列文本即Docker安装成功,可正常使用

[root@xjx-centos-linux-8 xjx]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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/

[root@xjx-centos-linux-8 xjx]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   5 months ago   13.3kB
[root@xjx-centos-linux-8 xjx]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@xjx-centos-linux-8 xjx]# docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED              STATUS                          PORTS     NAMES
2fbaf8a697f9   hello-world   "/hello"   About a minute ago   Exited (0) About a minute ago             nervous_goldberg
Logo

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

更多推荐