Docker 鏡像推送至 Coding 制品倉庫超時問題排查與解決
在將 Docker 鏡像推送至 Coding 的制品倉庫時,可能會遇到 docker push
命令超時失敗的問題。但使用 curl -i http://xxx.coding.xxxx.xx
測試時,連接卻能成功建立。以下是排查過程及解決方案。
問題排查
1. 域名解析檢查
首先,我們需要排查網絡連接問題,特別是域名解析是否正常。可以通過執行 nslookup
命令來進行檢查。
# 檢查域名能否解析
nslookup xxx.coding.xxxx.xx
如果該命令能正常返回域名對應的 IP 地址,說明域名解析功能正常。
2. 端口連通性測試
接著使用telnet命令,測試目標端口443的連通性,根據telnet
測試結果(Connection refused
),問題已明確:客戶端能解析 Coding 倉庫域名,但端口443拒絕連接
# 檢查端口連通性(需安裝telnet)
telnet xxx.coding.xxxx.xx 443
初步推測是因為docker push
命令默認使用 HTTPS 協議,而 Coding 倉庫使用的是 HTTP 協議
解決方案
1. 配置 Docker 信任 HTTP 倉庫
要讓 Docker 能夠與使用 HTTP 協議的私有鏡像倉庫進行通信,需要在 Docker 配置中添加 insecure-registries
# 1. 編輯Docker配置文件
vim /etc/docker/daemon.json# 2. 添加以下內容
{"insecure-registries": ["xxx.coding.xxxx.xx"]
}# 3. 重啟Docker服務
sudo systemctl restart docker
2. 驗證配置是否生效
配置完成后,需要驗證 insecure-registries
配置是否已成功添加到 Docker 配置中
# 檢查Docker配置是否包含insecure-registries
docker info | grep -A5 'Insecure Registries'# 預期輸出示例:
# Insecure Registries:
# xxx.coding.xxxx.xx
# 127.0.0.0/8
3. 重新登錄并推送鏡像
完成配置驗證后,就可以使用 HTTP 協議重新登錄 Coding 倉庫,并推送 Docker 鏡像了
# 使用HTTP協議登錄(無需指定端口,默認80)
docker login xxx.coding.xxxx.xx -u your_username -p your_password# 推送鏡像(確保鏡像標簽包含倉庫域名)
docker tag your-image:tag xxx.coding.xxxx.xx/your-image:tag
docker push xxx.coding.xxxx.xx/your-image:tag