Skip to content

Docker 安装

Published: at 08:00 AM

目前国内服务器厂商已经不能正常访问:download.docker.com 域名,也就无法安装 docker 服务。

报错:

Err:9 https://download.docker.com/linux/debian bookworm InRelease
  Cannot initiate the connection to download.docker.com:443 (2a03:2880:f10c:283:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (108.160.169.178), connection timed out
Reading package lists... Done
W: Failed to fetch https://download.docker.com/linux/debian/dists/bookworm/InRelease  Cannot initiate the connection to download.docker.com:443 (2a03:2880:f10c:283:face:b00c:0:25de). - connect (101: Network is unreachable) Could not connect to download.docker.com:443 (108.160.169.178), connection timed out

这里使用阿里云镜像进行安装,环境为 Debian,如使用 Ubuntu 将域名中 https://mirrors.aliyun.com/docker-ce/linux/debian/gpg debian 替换为 ubuntu 即可。

也可使用腾讯云镜像:https://mirrors.cloud.tencent.com/docker-ce/linux/debian/gpg

添加 Docker 仓库

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
# sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg -o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/debian \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

安装

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

运行 hello-world

sudo docker run hello-world

配置镜像加速源

阿里云

容器镜像服务

针对Docker客户端版本大于 1.10.0 的用户

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

注意:putyoumirror 替换成自己的。

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://putyoumirror.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

腾讯云

registry-mirrors 更改腾讯的源即可

{
   "registry-mirrors": [
   "https://mirror.ccs.tencentyun.com"
  ]
}

参考