Docker 镜像

Summary: Author: 张亚飞 | Read Time: 2 minute read | Published: 2000-02-02
Filed under Categories: MarkDownTags: Tag,

Docker 安装镜像

Docker / Kubernetes 镜像源不可用,教你几招搞定它! docker/kubernetes国内源/镜像源解决方式


配置使用 http_proxy 代理

/etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://127.0.0.1:1080/" "NO_PROXY=localhost,127.0.0.1,registry.ioros.com,repository.ioros.com"

/etc/systemd/system/docker.service.d/https-proxy.conf

[Service]
Environment="HTTPS_PROXY=http://127.0.0.1:1080/" "NO_PROXY=localhost,127.0.0.1,registry.ioros.com,repository.ioros.com"

验证配置是否生效

sudo systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://127.0.0.1:1080/ NO_PROXY=localhost,127.0.0.1,registry.ioros.com,repository.ioros.com HTTPS_PROXY=http://127.0.0.1:1080/
  • 常见问题

Docker 在 No Proxy 配置了 registry.cn-hangzhou.aliyuncs.com 但是仍无法跳过代理下载镜像

$ docker info
Server:
 HTTP Proxy: http://127.0.0.1:1080/
 HTTPS Proxy: http://127.0.0.1:1080/
 No Proxy: localhost,127.0.0.1,docker.io,registry.docker-cn.com,8grw9pfg.mirror.aliyuncs.com,registry.cn-hongkong.aliyuncs.com,registry.cn-hangzhou.aliyuncs.com,registry.cn-shanghai.aliyuncs.com,harbor.baijiayun.com,registry.ioros.com,repository.ioros.com
 Registry: https://index.docker.io/v1/

构建镜像报以下错误:

Step 1/8 : FROM registry.cn-hangzhou.aliyuncs.com/coam/us.mysql:20.11.11 as builder
Get https://registry.cn-hangzhou.aliyuncs.com/v2/coam/us.mysql/manifests/20.11.11: Get https://dockerauth.cn-hangzhou.aliyuncs.com/auth?scope=repository%3Acoam%2Fus.mysql%3Apull&service=registry.aliyuncs.com%3Acn-hangzhou%3A26842: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

直接使用 docker image pull 拉取镜像仍报错

$ docker image pull registry.cn-hangzhou.aliyuncs.com/coam/us.mysql:20.11.11
Error response from daemon: Get https://registry.cn-hangzhou.aliyuncs.com/v2/coam/us.mysql/manifests/20.11.11: Get https://dockerauth.cn-hangzhou.aliyuncs.com/auth?scope=repository%3Acoam%2Fus.mysql%3Apull&service=registry.aliyuncs.com%3Acn-hangzhou%3A26842: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

只有将 ShadowSocks 代理服务器开启才可以拉镜像了,并且是使用 ShadowSocks 代理服务器的流量 在网上查到原因貌似还需要走 https://dockerauth.cn-hangzhou.aliyuncs.com 等其它授权服务器,于是改成如下配置

$ docker info
Server:
 HTTP Proxy: http://127.0.0.1:1080/
 HTTPS Proxy: http://127.0.0.1:1080/
 No Proxy: localhost,127.0.0.1,docker.io,registry.docker-cn.com,*.aliyuncs.com,harbor.baijiayun.com,registry.ioros.com,repository.ioros.com
 Registry: https://index.docker.io/v1/

*,registry.cn-hangzhou.aliyuncs.com 改成了 *.aliyuncs.com 简洁了不少,再次拉取成功,试了把 ShadowSocks 代理服务器关了也可以拉取成功.

参考列表


Comments

Cor-Ethan, the beverage → www.iirii.com