English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Background
In some laboratory environments, servers do not have direct access to the internet and need to use a network proxy. We usually configure the network proxy directly in/etc/environment,/etc/profile and other configuration files, which is feasible for most operations. However, docker commands cannot use these proxies.
For example, when pulling images with docker pull, you may need to download the image from the internet, and the following error may occur:
$ docker pull hello-world Unable to find image 'hello-world:latest' locally Pulling repository docker.io/library/hello-world docker: Network timeout occurred while trying to connect to https://index.docker.io/v1/repositories/library/hello-world/images. You may want to check your internet connection or if you are behind a proxy.. See 'docker run --help'.
ps: This article is written in Ubuntu16.04Pass the test below.
Solution One:
Stop the docker service, manually use2375Start the docker daemon with port listening on all network interfaces.
$ systemctl stop docker.service $ nohup docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock &
Solution Two:
Edit the configuration file, in Ubuntu it is/etc/default/docker, in CentOS it is/etc/sysconfig/docker. However, modifying these two files to configure the daemon is discouraged. This method is not recommended.
HTTP_PROXY="http://[proxy-addr]:[proxy-port]/" HTTPS_PROXY="https://[proxy-addr]:[proxy-port]/" export HTTP_PROXY HTTPS_PROXY
Solution three:
This method is persistent, and the modification will take effect permanently. This method overrides the default docker.service file.
1. Create an embedded systemd directory for the docker service
$ mkdir -p /etc/systemd/system/docker.service.d
2. Create/etc/systemd/system/docker.service.d/http-proxy.conf file, and add the HTTP_PROXY environment variable. Among [proxy-addr] and [proxy-port] respectively change to the actual proxy address and port:
[Service] Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/"HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/"
3. If there are any internal Docker registries that do not need to use a proxy to access, then you need to specify the NO_PROXY environment variable:
[Service] Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/"HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/"NO_PROXY=localhost"127.0.0.1,docker-registry.somecorporation.com"
4. Update configuration:
$ systemctl daemon-reload
5. Restart Docker service:
$ systemctl restart docker
That's all for this article. I hope it will be helpful to your studies, and I also hope everyone will support the Yell Tutorial.
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)