在CentOS8中安装Docker步骤

1 参考Docker官方步骤进行操作,但是会提示:
错误:
 问题: package docker-ce-3:19.03.3-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.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
2 执行以下命令

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

yum update -y
4 依赖包(可选)

yum install -y conntrack  ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
systemctl stop firewalld && systemctl disable firewalld
yum install -y iptables-services
systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
5 安装官方教程进行安装 (如果Centos是7.4或者7.6只需要直接按照以下三步就可以)
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

yum install -y docker-ce docker-ce-cli containerd.io
6 安装完毕后,启动服务并设置成自启动

systemctl enable docker && systemctl start docker
扩展----------------------------------------------

7 设置Docker的日志为JSON格式,在 /etc/docker目录中 创建以下文件
*注: docker默认cgroupdriver为cgroup,k8s使用systemd

vi /etc/docker/daemon.json

{
"registry-mirrors": ["https://hpb3jxjv.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver":"json-file",
"log-opts":{
 "max-size":"200m"
}
}
8 创建目录,用于存放docker的配置文件

mkdir -p /etc/systemd/system/docker.service.d
9 重启

systemctl daemon-reload && systemctl restart docker && systemctl enable docker