https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
# 这一步需要使用代理才能成功
sudo curl -x http://127.0.0.1:7890 -fsSL https://download.docker.com/linux/ubuntu/gpg -o /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://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
这一步会失败:
Err:7 https://download.docker.com/linux/ubuntu focal InRelease
Could not connect to download.docker.com:443 (2a03:2880:f129:83:face:b00c:0:25de), connection timed out Could not connect to download.docker.com:443 (179.60.193.16), connection timed out
Fetched 2,910 B in 36s (81 B/s)
Reading package lists... Done
W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/focal/InRelease Could not connect to download.docker.com:443 (2a03:2880:f129:83:face:b00c:0:25de), connection timed out Could not connect to download.docker.com:443 (179.60.193.16), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.
我已经开启了代理,还是失败:
curl -x http://127.0.0.1:7890 -I https://download.docker.com
HTTP/1.1 200 Connection established
HTTP/2 200
content-type: text/html
content-length: 223
date: Fri, 21 Jun 2024 11:21:25 GMT
last-modified: Fri, 21 Jun 2024 11:11:17 GMT
etag: "5a2449544577bdf952c47cdc248220b4"
server: AmazonS3
x-cache: Hit from cloudfront
via: 1.1 7110543e95ede37ef1cea5dbc0cc94a4.cloudfront.net (CloudFront)
x-amz-cf-pop: HKG54-C1
x-amz-cf-id: ZNtewk2gzVHfFsAibNf2Y-8N0_y2OWHQ5tIKHvmLuFX5hj5KbsDwwg==
age: 83765
从 curl 的输出可以看出,通过代理成功连接到了 Docker 的服务器,说明代理配置是正确的。接下来我们需要确保 APT 也能使用代理并成功连接到服务器。
配置 APT 使用代理
确保 APT 使用了正确的代理设置。编辑或创建 /etc/apt/apt.conf 文件:
sudo nano /etc/apt/apt.conf
添加以下内容:
Acquire::http::Proxy "http://127.0.0.1:7890";
Acquire::https::Proxy "http://127.0.0.1:7890";
保存并退出。
再次尝试更新和安装 Docker
现在尝试更新 APT 并安装 Docker:
sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify that the Docker Engine installation is successful by running the hello-world image.
sudo docker run hello-world
标签:安装,sudo,apt,https,download,docker,com
From: https://www.cnblogs.com/odesey/p/18262624