Skip to content

Docker Install 在 CentOS 环境

Docker 官方文档: https://docs.docker.com/install/linux/docker-ce/centos/

添加添加软件源信息

bash
# 由于国内较慢,添加添加软件源信息
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

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

# 或者:上面命令的功能也可以如下方式实现
cd /etc/yum.repos.d
wget https://download.docker.com/linux/centos/docker-ce.repo

# CentOS 7 更新yum缓存
sudo yum makecache fast
# CentOS 8
dnf makecache

# 1. Install the latest version of Docker CE (CentOS 7)
sudo yum install docker-ce -y

# CentOS 8 可能会报错
# 经过排查发现 buildah-1:1.24.2-2.module_el8.7.0+1106+45480ee0.x86_64 冲突了, 需要移除掉。
# 需要在安装命令后加上 --allowerasing ,用来 替换冲突的软件包
sudo yum install docker-ce --allowerasing -y

# 2. Start Docker
sudo systemctl start docker

# 3. 开机自动启动
sudo systemctl enable docker

卸载

shell
yum remove docker-ce

配置镜像加速器

您可以通过修改 daemon 配置文件/etc/docker/daemon.json 来使用加速器

并且可以选择配置 k8s 运行要求 docker 的--cgroup-driver=systemd

shell
sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://huecker.io",
    "https://dockerhub.timeweb.cloud",
    "https://noohub.ru"
  ],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

Docker Hub 镜像加速器

Dockerized 实践