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