Centos8安装docker容器及遇到问题解决
- 进入Docker文档,查看Install Centos的官方文档
- 卸载旧的版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
-
设置Docker存储库
- 在首次安装 Docker 引擎之前,您需要设置 Docker 存储库。之后,可以从存储库安装和更新 Docker。
$ sudo yum install -y yum-utils
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
- 安装最新版本的Docker 引擎和容器
$ sudo yum install docker-ce docker-ce-cli containerd.io
Error:
Problem: package docker-ce-3:19.03.12-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
-cannot install the best candidate for the job
-package containerd.io-1.2.10-3.2.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.13-3.1.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.13-3.2.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.2-3.3.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.2-3.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.4-3.1.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.5-3.1.el7.x86_64 is filtered out by modular filtering
-package containerd.io-1.2.6-3.3.el7.x86_64 is filtered out by modular filtering
(try to add ‘–skip-broken’ to skip uninstallable packages or ‘–nobest’ to use not only best candidate packages)
1. 首先更新yum
$ yum update
2. 以下方法任选一种
# 方法1: 安装特定版本的docker-ce和containerd.io
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
# 方法2: 通过阿里云镜像库安装符合最新docker-ce版本的containerd.io
$ yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
- 异常解决后,再次执行安装命令
$ sudo yum install docker-ce docker-ce-cli containerd.io
- 安装成功命令行界面
- 验证是否安装成功
# 此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条信息性消息并退出。
$ sudo docker run hello-world
- 启动和停止Docker
# 启动 Docker
$ sudo systemctl start docker
# 重启docker
systemctl restart docker
# 停止docker
systemctl stop docker
# 设置开机启动docker
systemctl enable docker
- 卸载Docker
# 卸载 Docker 引擎、CLI 和容器包
$ sudo yum remove docker-ce docker-ce-cli containerd.io
# 要删除所有镜像、容器和卷:
$ sudo rm -rf /var/lib/docker