Detail setting up the agent for Docker

  • 2020-06-12 11:14:46
  • OfStack

Domestic use of Docker has struggled for well-known reasons. As a result, many organizations in the country to provide mirror Or call 加速器 .

I even mentioned in release note in 1.13 that Microsoft provided the official China image, but I didn't find how to enable it, so I wrote it later.

Using these images or accelerators, the various official images are ok, and the own images can also be placed domestically registry .

But the official mirror image is a drop in the ocean, and a large number of organizations and individuals are there docker hub , this part is not mirrored synchronously.

So you still need an agent.

This paper assumes:

You already have an http agent

The Linux distribution's service manager USES systemd This article was written on Version 17.03.0-ES29en and is available on Docker 1.13 and 17.03. Changes will not be ruled out in the future By the way, the Windows version sets up agents directly on the Settings GUI.

About systemd

Many of you may not be familiar with systemd, but with all the major distributions switched to systemd, it's worth knowing.


#  restart docker
$ sudo systemctl restart docker
#  Corresponding to the old command, in fact now still support, effect and on 1 other 1 The sample. 
$ sudo service docker restart
#  Set boot up 
$ sudo systemctl enable docker

systemd Is made up of folders /lib/systemd/system In the docker.service File defined.

We can easily search for 1 systemd tutorial and see how to write 1 service file by ourselves.

So you may be tempted to change the file 1, the agent to add it.

Wait, don't worry, if you are doing your own service, of course, you have to write the file yourself. However, our docker is installed from an official source.

This means that if you change this file, it will take effect, but if you upgrade docker1, it will be overwritten. systemd certainly has a solution to this problem.

You really only have to create 1 call <something>.conf The name of the configuration file, randomly named, in
/etc/systemd/system/docker.service.d Directory. You override the default launch configuration, and it will exist as your user configuration 1.

HTTP proxy

Ok, now we are ready to add the agent configuration.

By default this configuration folder does not exist and we will create it.


$ mkdir -p /etc/systemd/system/docker.service.d

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

contains 加速器0 Environment variables:


[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/"

If there is a LAN or domestic registry, we also need to use NO_PROXY variable declaration 1, for example, you can put the domestic ES87en. io mirror:


[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80/" "NO_PROXY=localhost,127.0.0.1,daocloud.io"

Refresh systemd configuration:


$ sudo systemctl daemon-reload

Verify the environment variable with the system command:


$ systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://proxy.example.com:80/

Everything is ready to restart docker and take a tour of the outside world:


$ sudo systemctl restart docker

Related articles: