In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to elegantly configure the network agent for Docker, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.
Sometimes you need to use an agent for network reasons, such as a company NAT, or something else. The proxy configuration for Docker is slightly more complex because there are three scenarios. But the basic principles are consistent, using Linux's http_proxy and other environment variables.
Dockerd Agent
When the docker pull is executed, it is executed by the daemon dockerd. Therefore, the agent needs to be located in the environment of dockerd. This environment is controlled by systemd, so it is actually the configuration of systemd.
Sudo mkdir-p / etc/systemd/system/docker.service.d sudo touch / etc/systemd/system/docker.service.d/proxy.conf
In the proxy.conf file (which can be any form of * .conf), add the following:
[Service] Environment= "HTTP_PROXY= http://proxy.example.com:8080/" Environment=" HTTPS_PROXY= http://proxy.example.com:8080/" Environment= "NO_PROXY=localhost,127.0.0.1,.example.com"
Among them, proxy.example.com:8080 should be replaced with an available secret-free agent. Cntlm is usually used to build a self-built secret-free agent on this machine to dock with the company's agent. Please refer to "install and configure Cntlm Agent under Linux".
Container Agent
In the container running phase, if you need an agent to surf the Internet, you need to configure ~ / .docker / config.json. The following configuration is valid only for Docker version 17.07and above.
{"proxies": {"default": {"httpProxy": "http://proxy.example.com:8080"," httpsProxy ":" http://proxy.example.com:8080", "noProxy": "localhost,127.0.0.1,.example.com"}
This is a user-level configuration, in addition to proxies,docker login and other related information will also be included. You can also configure the format of the information display, plug-in parameters, and so on.
In addition, the container's network agent can also directly inject environment variables such as http_proxy through-e when it is running. These two methods are suitable for different scenarios. Config.json is very convenient. By default, all containers launched after configuration changes take effect, which is suitable for personal development environment. In CI/CD 's automated build environment, or in an environment where the line is actually running, this approach is not appropriate, and explicit configuration with-e injection is better, reducing dependence on the build and deployment environment. Of course, in these environments, it is best to use good design to avoid configuring agents to access the Internet.
Docker Build Agent
Although the essence of docker build is to launch a container, the environment is slightly different and the user-level configuration is invalid. When building, you need to inject parameters such as http_proxy.
Docker build. \-build-arg "HTTP_PROXY= http://proxy.example.com:8080/"\-build-arg" HTTPS_PROXY= http://proxy.example.com:8080/"\-build-arg "NO_PROXY=localhost,127.0.0.1,.example.com"\-t your/image:tag
Note: whether it is docker run or docker build, the default is network isolation. If the agent is using a class such as localhost:3128, it will be invalid. This type of local-only agent must be added with-- network host to work properly. In general, you need to configure the external IP of the agent, and the agent itself needs to turn on the Gateway mode.
Restart takes effect
After the proxy configuration is completed, the reboot restart can take effect, but it is OK if you don't have to restart it.
The docker build agent is set before execution, so the next execution takes effect immediately after modification. The changes to the Container agent also take effect immediately, but only for Container that is started later, and not for Container that has already been started.
The modification of the dockerd agent is special, it actually changes the configuration of systemd, so you need to reload systemd and restart dockerd to take effect.
Sudo systemctl daemon-reload sudo systemctl restart docker thank you for reading this article carefully. I hope the article "how to gracefully configure a network agent for Docker" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.