Common proxy configuration.
This is an automatically translated post by LLM. The original post is in Chinese. If you find any translation errors, please leave a comment to help me improve the translation. Thanks!
In the development process, due to well-known reasons, it is inevitable to use proxies. However, the ways in which various software uses proxies are different. This article provides a simple summary of proxy settings for commonly used software.
Shell
The most convenient way is to directly set the proxy in the command
line. This way, most programs executed in the command line will use the
proxy settings as follows: 1
2export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
You can also write the above commands into the ~/.bashrc
file for automatic execution.
For ease of writing, the default port 7890 of the software
CatHead
is used here. Modify it according to the proxy server port when actually using.
Docker
Proxy usage in Docker mainly falls into the following scenarios:
- Docker itself downloads images through a proxy.
- When building images with
docker build
, commands executed use a proxy for access. - When running containers with
docker run
, the containers internally use the host machine's proxy for access.
Next, we will explain the proxy configuration for these scenarios one by one.
1. Docker Proxy Configuration
When executing docker pull
, it is done by the daemon
dockerd
. Therefore, the proxy needs to be configured in the
environment of dockerd
, which is controlled by
systemd
. Thus, it is actually a configuration of
systemd
.
1 | sudo mkdir -p /etc/systemd/system/docker.service.d |
In this proxy.conf
file (can be in any *.conf form), add
the following content:
1 | [Service] |
Restart for changes to take effect:
1 | sudo systemctl daemon-reload |
2. Docker Build Proxy Configuration
1 | docker build \ |
3. Docker Run Proxy Configuration
Docker run uses host proxy.
Wget
wget
is commonly used for file downloads and sometimes
requires a proxy. There are three main ways wget
accesses
through a proxy:
Directly set system environment variables.
Modify the configuration file:
Edit the configuration file:
1
vim ~/.wgetrc
Write the following content:
1
2
3http_proxy=http://127.0.0.1:7890
https_proxy=http://127.0.0.1:7890
use_proxy=onUse the
-e
parameter:1
wget -e "http_proxy=http://127.0.0.1:7890" -e "https_proxy=http://127.0.0.1:7890" https://google.com
Microsoft Store
This needs to be discussed separately(calling out) because
it not only does not use system proxies but also fails to connect to
servers after enabling system proxies.
1 | CheckNetIsolation.exe loopbackexempt -a -p=S-1-15-2-1609473798-1231923017-684268153-4268514328-882773646-2760585773-1760938157 |