配置docker

记录CentOS7配置docker的过程

CentOS7

查看是否已安装

1
docker --version

若已安装:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine \
                  docker-ce

安装依赖工具 yum

1
sudo yum install -y yum-utils device-mapper-persistent-data lvm2

错误:yum-config-manager:找不到命令

yum -y install yum-utils

错误:更新 yum 报错

sudo tee /etc/yum.repos.d/CentOS-Base.repo «-‘EOF’ [base] name=CentOS-$releasever - Base baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates] name=CentOS-$releasever - Updates baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[extras] name=CentOS-$releasever - Extras baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

安装docker

添加 docker 官方仓库

1
2
3
4
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

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

安装

1
sudo yum install -y docker-ce docker-ce-cli containerd.io

启动、设置开机自启

1
2
sudo systemctl start docker
sudo systemctl enable docker

docker 拉取镜像源配置

添加多个镜像源

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://alzgoonw.mirror.aliyuncs.com",
    "https://docker.m.daocloud.io",
    "https://dockerhub.icu",
    "https://docker.anyhub.us.kg",
    "https://docker.1panel.live"
  ]
}

EOF

重新加载并重启

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

测试

1
docker pull hello-world

Ubuntu

删除无效的密钥文件

1
rm -f /etc/apt/trusted.gpg.d/docker.gpg

更换方式获取 Docker GPG 密钥

1
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg

替换 Docker 源为国内镜像

1
2
3
4
# 删除原有Docker源
rm -f /etc/apt/sources.list.d/docker.list
# 添加阿里云Docker源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null

更新源并安装 Docker

1
apt update && apt install -y docker-ce docker-ce-cli containerd.io

docker 配置

1
2
sudo systemctl start docker
sudo systemctl enable docker

添加多个[镜像源](国内可用 Docker 镜像源 - 长期维护更新 | 解决 Docker Hub 拉取慢/失败 - 土薯在线工具)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://alzgoonw.mirror.aliyuncs.com",
    "https://docker.m.daocloud.io",
    "https://dockerhub.icu",
    "https://docker.anyhub.us.kg",
    "https://docker.1panel.live"
  ]
}

EOF

重新加载并重启

1
2
sudo systemctl daemon-reload
sudo systemctl restart docker

测试

1
docker pull hello-world

配置 clash

克隆安装脚本

1
2
3
git clone --branch master --depth 1 https://github.com/nelvko/clash-for-linux-install.git \
   && cd clash-for-linux-install \
   && sudo bash install.sh

检查安装状态

1
clashctl status

获取 Web 控制台地址

1
clashctl ui

其他

Tun模式:clashctl tun on

docker 的代理需要额外配置

LXC 中使用 docker

参考:SOLVED - Docker inside LXC (net.ipv4.ip_unprivileged_port_start error) | Proxmox Support Forum

可能在启动时会有问题,要找指定版本!

版本选择依据

  1. 避开有 bug 的版本:论坛明确 1.7.28-2 及更高版本(如 1.7.29-12.1.5-1)会触发 LXC 中 Docker 修改 net.ipv4.ip_unprivileged_port_start 的权限错误,必须选择低于 1.7.28-2 的版本。
  2. 选择最接近的稳定版本1.7.28-1~ubuntu.24.04~noble1.7.28-2 的前一个版本,仅差小版本修复,功能完整且无该兼容性 bug,比更旧的 1.7.27-1/1.7.26-1 更推荐(减少版本回退带来的其他兼容性问题)。
Licensed under Calendar