docker study notes docker connection Settings

  • 2020-06-07 05:37:03
  • OfStack

1. If the docker host does not need to connect to the external network through the proxy

Then docker related commands (such as docker search) or docker containers can perform network-related operations without special Settings.

2. When the docker host can only connect to the external network through the proxy, start the daemon process in a service manner

If the docker daemon is started as a service (sudo start docker)

An error is reported when we execute commands such as docker search ubuntu

Error response from daemon: Get https://index.docker.io/v1/search?q=ubuntu: dial tcp: lookup index.docker.io on 127.0.1.1:53: read udp 127.0.1.1:53: i/o timeout

Also, the container that starts at this time cannot connect to the external network inside the container.

This needs to be done through Settings.

3. When the docker host can only connect to the external network through the proxy, let the docker daemon connect to the external network without starting the service

Start the docker daemon as follows


sudo HTTP_PROXY=http:// Address of the agent : port  docker daemon

When you execute a command like docker search ubuntu, it succeeds. Note that this does not require the docker host itself to set up the proxy (that is, the docker process does not use the proxy set up by the host).

But containers that start up normally cannot be connected to the outer network within the container.

4. When the docker host can only connect to the external network through the proxy, it shall be started by service

You can modify the /etc/default/docker configuration file


# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"
export http_proxy="http:// Address of the agent : port "

After starting the daemon process in sudo start docker mode

This will succeed if you execute command docker search ubuntu.

Note that this does not require the docker host to set up the proxy itself (that is, the docker process does not use the proxy set up by the host).

But containers that start up normally cannot be connected to the outer network within the container.

5, how to let the container through the proxy Internet

The container itself is a lightweight linux system that can be networked by setting up the host to do the same. The container has nothing to do with networking the docker daemons.

Method 1: Temporary networking

Set the temporary environment variable on the shell interface: export http_proxy="http:// proxy ip address: port"

Such as:


export http_proxy=http://10.41.70.8:80

Once the correct environment variable http_proxy is set, the container can surf the Internet normally.

Because it is temporary, the environment variable disappears when shell is closed.

Method 2: Modify the.bashrc file in your home directory by adding two lines


http_proxy=http://yourproxyaddress:proxyport
export http_proxy

Persist the environment variable http_proxy, but only for that user's login.

Note: The container setup proxy is independent of the docker host setup proxy and the docker daemon setup proxy, meaning that the container will only use its own proxy information to surf the Web.


Related articles: