記錄一下遇到的狀況.

要自己build image的時候, 要先拉一份外面的image, 但因為外網不會通, 所以要透過proxy server出去.

本來以為用export就可以, 實際上測試是要另外輸入參數或是要在build/pull當下帶參數.

Set build-time variables

Example 當下帶指令

docker build --build-arg HTTP_PROXY=http://<ip>:<port> .

Example export

export HTTP_Proxy=http://<ip>:<port>
docker build --build-arg HTTP_PROXY .

最後決定一勞永逸, 直接設定DockerProxy

建立資料夾並進入到資料夾內

mkdir -p /etc/systemd/system/docker.service.d
cd /etc/systemd/system/docker.service.d

新增檔案並寫入

vim http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://<ip>:<port>"
Environment="HTTPS_PROXY=http://<ip>:<port>"

重新讀取 & 重啟服務

systemctl daemon-reload
systemctl restart docker

然後再pull一次就可以了

docker pull ubuntu:latest

Ref