Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the network proxy in the Docker container

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to set up a network proxy in the Docker container? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Set environment variabl

Setting the container environment variable is also the most direct way. When you start the container, you pass the environment variables into the container by setting the flag of-- env.

Dockerfile sample Docker run example HTTP_PROXYENV HTTP_PROXY "http://127.0.0.1:3001"--env HTTP_PROXY=" http://127.0.0.1:3001"HTTPS_PROXYENV HTTPS_PROXY "https://127.0.0.1:3001"--env HTTPS_PROXY=" https://127.0.0.1:3001"FTP_PROXYENV FTP_PROXY "ftp://127.0.0.1:3001"--env FTP_ PROXY= "ftp://127.0.0.1:3001"NO_PROXYENV NO_PROXY" * .test.example.com .example2.com "--env NO_PROXY=" * .test.example.com, .example2.com "

The advantage of this approach is straightforward, but the disadvantage is that every time you start the container, you need to display the settings, so you will have trouble compiling some projects. For example, the kubevirt project will start the container to download the go project in the code, and you need to use a proxy, so you must manually find the location of the startup container, and the display plus the above environment variables increases a lot of work. To solve this situation, you can configure the Docker client above Docker 17.07.

Configure the Docker client

Precondition: Docker 17.07or above.

In the Home directory of the docker user, create the ~ / .docker / config.json file and add the settings for http_proxy, https_proxy, ftp_proxy, etc. Of course, you can also configure multiple proxy servers at the same time.

For paths that do not want to use no_proxy, you can also add the configuration of no_proxy. The contents of no_proxy are separated by commas and the wildcard character * is supported.

Example:

{"proxies": {"default": {"httpProxy": "http://127.0.0.1:3001"," httpsProxy ":" http://127.0.0.1:3001", "noProxy": "* .test.example.com, .example2.com"}

Start the container and you can see that the agent will be automatically added to the container.

This is the answer to the question about how to set up a network proxy in the Docker container. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report