公司网络中连接Docker.io的方法

宿主机(host)是Ubuntu 22.04,在公司的网络中运行docker pull ubuntu会显示网络连接超时。试过在/etc/default/docker中加代理,也试过在命令行中加代理,皆不起作用。

直到看到这个贴子才解决问题, https://forums.docker.com/t/proxy-settings-do-not-work-for-either-etc-default-docker-or-systemd-drop-ins/68891/3

root@manager:~# mkdir -p /etc/systemd/system/docker.service.d
root@manager:~# echo -e "[Service]\nEnvironment=\"HTTP_PROXY=http://proxy.example.com:80/\"" > /etc/systemd/system/docker.service.d/https-proxy.conf
root@manager:~# sudo systemctl daemon-reload
root@manager:~# sudo systemctl restart docker
root@manager:~# systemctl show --property=Environment docker
Environment=HTTPS_PROXY=http://proxy.example.com:80/
$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
7c3b88808835: Pull complete 
Digest: sha256:8ae9bafbb64f63a50caab98fd3a5e37b3eb837a3e0780b78e5218e63193961f9
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

做一个简单的Dockerfile

FROM ubuntu
ENV http_proxy <HTTP_PROXY>
RUN apt-get update &amp;&amp; apt-get install -y curl
$ sudo docker build -t curl .
Sending build context to Docker daemon  4.608kB
Step 1/3 : FROM ubuntu
 ---> 2b4cba85892a
Step 2/3 : ENV http_proxy http://10.144.1.10:8080/
 ---> Running in 6ca885f013d9
Removing intermediate container 6ca885f013d9
 ---> 58b639cac759
Step 3/3 : RUN apt-get update && apt-get install -y curl
 ---> Running in b2fc4c5dab97
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
...

参考

https://www.cloudbees.com/blog/using-docker-behind-a-proxy
https://stackoverflow.com/questions/22179301/how-do-you-run-apt-get-in-a-dockerfile-behind-a-proxy

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容