【Docker学习-2】CentOS6,7,8安装docker(详细教程)
前提说明
查看自己的内核
uname -r
cat /etc/redhat-release
docker的基本组成
docker的架构图
docker三要素
Docker | 面向对象 |
---|---|
容器 | 对象 |
镜像 | 类 |
仓库 | 项目 |
这有三个容器,均来自与同一个模板,Person
CentOS6安装Docker
yum install -y epel-release
Docker使用EPEL发布,RHEL系的OS首先要确保已经持有EPEL仓库,否则先检查OS的版本,然后安装相应的EPEL包。
yum install docker-io
查看docker配置文件
docker的启动
service docker start
查看docker版本信息
docker version
CentOS7安装Docker
卸载老版本的Docker
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
安装需要的软件包
yum install -y yum-utils device-mapper-persistent-data lvm2
设置stable镜像仓库
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新yun软件包索引
yum makecache fast
安装DOCKER CE
yum -y install docker-ce
启动Docker
systemctl start docker
测试,查看版本,运行仓库
docker version
docker run hello-word
配置镜像加速
mkdir -p /etc/docker
vim /etc/docker/daemon.json
#网易云
{"registry-mirrors": ["http://hub-mirror.c.163.com"] }
#阿里云
{
"registry-mirrors": ["https://{自已的编码}.mirror.aliyuncs.com"]
}
systemctl daemon-reload
systemctl restart docker
CentOS8安装Docker
安装社区版Docker Engine
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
yum-config-manager --enable docker-ce-nightlyyum-config-manager --enable docker-ce-test
yum-config-manager --enable docker-ce-test
yum-config-manager --disable docker-ce-nightly
安装这一步报错
yum install docker-ce docker-ce-cli containerd.io
报错内容
[root@localhost yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io
Last metadata expiration check: 0:04:46 ago on Mon 16 Mar 2020 03:40:11 PM CST.
Package containerd.io-1.2.0-3.el7.x86_64 is already installed.
Error:
Problem: package docker-ce-3:19.03.8-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 excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.11-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.12-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.2.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
分析原因
看上面的内容,说的是containerd.io >= 1.2.2-3 ,意思就是 containerd.io 的版本必须大于等于 1.2.2-3
解决
如果不想降低docker 版本,那么就更新 containerd.io 的版本
yum install -y wget
wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
yum install -y containerd.io-1.2.6-3.3.el7.x86_64.rpm
yum install docker-ce docker-ce-cli
一直‘y’
启动 docker
systemctl start docker
检查是否安装成功
检查版本号
docker -v
返回版本信息
参考文章:https://www.backendcloud.cn/2020/03/16/centos8installdocker/