您的位置:首页 > 运维架构 > Docker

Centos8安装Docker

2021-07-27 19:16 579 查看

1、安装准备

如果有安装过docker,先卸载旧版本,命令如下:

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

2、安装

这里使用Docker仓库的方式安装

2.1、设置仓库

安装

yum-utils
包(提供
yum-config-manager
)并设置
docker
仓库,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2

使用官方仓库地址(比较慢)

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

可以选择国内的一些仓库地址

阿里云

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

清华大学

sudo yum-config-manager \
--add-repo \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

2.2 安装Docker Engine

安装最新版本的Docker Engine和 containerd

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

如果出现以下错误:

Error:
Problem 1: problem with installed package podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64
- package podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64 requires runc, but none of the providers can be installed
- package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
- package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- cannot install the best candidate for the job
- package runc-1.0.0-56.rc5.dev.git2abd837.module_el8.3.0+569+1bada2e4.x86_64 is filtered out by modular filtering
- package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered out by modular filtering
- package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered out by modular filtering
- package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering
- package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered out by modular filtering
Problem 2: problem with installed package cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch
- package cockpit-podman-4-1.module_el8.1.0+237+63e26edc.noarch requires podman >= 1.2.0, but none of the providers can be installed
- package cockpit-podman-29-2.module_el8.4.0+781+acf4c33b.noarch requires podman >= 1.3.0, but none of the providers can be installed
- package podman-3.0.1-6.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package docker-ce-3:20.10.7-3.el8.x86_64 requires containerd.io >= 1.4.1, but none of the providers can be installed
- package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.3-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.3-3.2.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.3-3.2.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- cannot install the best candidate for the job
- package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered out by modular filtering
- package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered out by modular filtering
- package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering
- package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered out by modular filtering
- package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.4-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.4-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.6-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package podman-3.0.1-7.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-57, but none of the providers can be installed
- package podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64 requires runc, but none of the providers can be installed
- package runc-1.0.0-56.rc5.dev.git2abd837.module_el8.3.0+569+1bada2e4.x86_64 is filtered out by modular filtering
- package podman-1.6.4-26.module_el8.4.0+793+f0dfa22d.x86_64 is filtered out by modular filtering
- package podman-3.0.1-6.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering

查看是否安装了Podman

rpm -q podman
结果:
--podman-1.4.2-5.module_el8.1.0+237+63e26edc.x86_64

已经安装了

podman
,删除Podman

dnf remove podman

再执行安装命令,发现还报如下错误:

Error:
Problem: problem with installed package buildah-1.9.0-5.module_el8.1.0+237+63e26edc.x86_64
- package buildah-1.9.0-5.module_el8.1.0+237+63e26edc.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package buildah-1.19.7-1.module_el8.4.0+781+acf4c33b.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package buildah-1.19.7-2.module_el8.4.0+830+8027e1c4.x86_64 requires runc >= 1.0.0-26, but none of the providers can be installed
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-60.rc8.module_el8.1.0+237+63e26edc.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-70.rc92.module_el8.4.0+673+eabfc99d.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 conflicts with runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- package containerd.io-1.4.8-3.1.el8.x86_64 obsoletes runc provided by runc-1.0.0-73.rc93.module_el8.4.0+830+8027e1c4.x86_64
- cannot install the best candidate for the job
- package runc-1.0.0-56.rc5.dev.git2abd837.module_el8.3.0+569+1bada2e4.x86_64 is filtered out by modular filtering
- package runc-1.0.0-64.rc10.module_el8.4.0+522+66908d0c.x86_64 is filtered out by modular filtering
- package runc-1.0.0-65.rc10.module_el8.4.0+819+4afbd1d6.x86_64 is filtered out by modular filtering
- package runc-1.0.0-70.rc92.module_el8.4.0+786+4668b267.x86_64 is filtered out by modular filtering
- package runc-1.0.0-71.rc92.module_el8.4.0+833+9763146c.x86_64 is filtered out by modular filtering

同样使用上面检查

podman
的方式处理,然后再执行安装命令,就可以了,然后跟着提示操作就行。 安装成功最后会提示如下:

Installed:
container-selinux-2:2.162.0-1.module_el8.4.0+830+8027e1c4.noarch    containerd.io-1.4.8-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
docker-ce-rootless-extras-20.10.7-3.el8.x86_64                      docker-scan-plugin-0.8.0-3.el8.x86_64    fuse-common-3.2.1-12.el8.x86_64     fuse-overlayfs-1.4.0-3.module_el8.4.0+830+8027e1c4.x86_64
fuse3-3.2.1-12.el8.x86_64                                           fuse3-libs-3.2.1-12.el8.x86_64           libcgroup-0.41-19.el8.x86_64        libslirp-4.3.1-1.module_el8.4.0+575+63b40ad7.x86_64
slirp4netns-1.1.8-1.module_el8.4.0+641+6116a774.x86_64

2.3、查看Docker其他版本

如果不想安装最新的版本,可以使用如下命令,查看其他版本。

yum list docker-ce --showduplicates | sort -r

Installed Packages
docker-ce.x86_64               3:20.10.7-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.7-3.el8                 @docker-ce-stable
docker-ce.x86_64               3:20.10.6-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.5-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.4-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.3-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.2-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.1-3.el8                 docker-ce-stable
docker-ce.x86_64               3:20.10.0-3.el8                 docker-ce-stable
docker-ce.x86_64               3:19.03.15-3.el8                docker-ce-stable
docker-ce.x86_64               3:19.03.14-3.el8                docker-ce-stable
docker-ce.x86_64               3:19.03.13-3.el8                docker-ce-stable

通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-19.03.13。

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
例如:
sudo yum install docker-ce-19.03.13 docker-ce-cli-19.03.13 containerd.io

2.4、启动Docker

sudo systemctl start docker

2.5、测试Docker安装情况

通过运行

hello-world
镜像验证
Docker Engine
是否安装成功

sudo docker run hello-world

看到如下信息,则代表

Docker
已经安装成功。

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/

从以上信息可以看出,

Docker
先在本地查看是否有
hello-world
镜像,如果没有就到远程仓库获取,可以运行如下命令,查看镜像。

docker images
结果:
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   4 months ago   13.3kB

可以看出,已经从远程仓库拉取到

hello-world
镜像到本地了。

3、设置开机启动Docker

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

禁用开机启动将

enable
改为
disabled

4、卸载Docker

删除安装包

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

删除镜像容器、配置文件等内容

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: