参考官方文档,
https://docs.docker.com/engine/install/centos/
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install docker-ce docker-ce-cli containerd.io
...
--> Finished Dependency Resolution
Error: Package: containerd.io-1.2.13-3.2.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
Error: Package: 3:docker-ce-19.03.12-3.el7.x86_64 (docker-ce-stable)
Requires: container-selinux >= 2:2.74
...
如下地址,下载 container-selinux 安装包 container-selinux-2.107-3.el7.noarch.rpm
http://mirror.centos.org/centos/7/extras/x86_64/Packages/
# rpm -ivh container-selinux-2.107-3.el7.noarch.rpm
重新执行安装命令,
# yum install docker-ce docker-ce-cli containerd.io
为了 non-root user 使用方便,
创建 group, (optional, 安装 docker 时会默认创建)
$ sudo groupadd docker
将用户加入 group,
$ sudo usermod -aG docker $USER
使 group 改动生效,
$ newgrp docker
设置 docker 随系统启动,
$ sudo systemctl enable docker
$ sudo chkconfig docker on
镜像加速,更改 registry 指向 Aliyun,
$ sudo mkdir -p /etc/docker
运行,
sudo tee /etc/docker/daemon.json <<-'EOF' # 从 stdin 得到数据,直到遇到 EOF 为止 { "registry-mirrors": ["https://********.mirror.aliyuncs.com"] # Aliyun 个人账户下的镜像加速地址 } EOF
重启服务,
sudo systemctl daemon-reload sudo systemctl restart docker
(完)