StableProxy
© StableProxy – 2021 - 2026 – Ukraine

StableProxy
© StableProxy – 2021 - 2026 – Ukraine

Step-by-step tutorial on how to configure a proxy server in Docker using the command line interface (CLI) and the config.json configuration file.
Олександр Л.
Proxy server configuration may be required on the Docker platform in a number of cases. The most common ones are bypassing web provider limits and testing software you developed across multiple geolocations. Let's start by looking at the concept of Docker.
Docker is a set of platform-as-a-service (PaaS) products that use OS-level virtualization to deliver software in packages called containers, that is, to perform containerization of packages. The service has different tiers based on payment: free and premium with advanced features. This software was released in 2013. In other words, Docker is a platform for developing, delivering, and running software, where you can separate your software from your infrastructure. Thus, the assembled container can be run on different operating systems. In addition, you will be pleased to know that the Docker platform supports SSL, which provides an excellent level of information and network security when working with it, in particular, when testing application performance. Containerized information contains:
There are 2 ways to configure it: via the command line and using a config file. Working in the command line looks like this:
proxy.example.com:Port parameter, you need to find out the IP address of your proxy and the port used.docker build command, which creates the config. It is necessary to use the --build-arg argument in it. The full command will look like this:
Bashdocker build --build-arg HTTP_PROXY="http://proxy.example.com:Port" .
docker run command to launch the created config. It is necessary to use the --env argument. The full command will look as follows:
Bashdocker run --env HTTP_PROXY="http://proxy.example.com:Port" redis
Configuring a Docker proxy using a config file looks like this:
.docker folder. It should contain a file named config.json. Create it if it is missing.{
"proxies": {
"default": {
"httpProxy": "http://proxy.example.com:Port",
"httpsProxy": "https://proxy.example.com:Port",
"ftpProxy": "https://proxy.example.com:Port",
"noProxy": "*.test.example.com,.example.org,127.0.0.0/8"
}
}
}
proxy.example.com:Port, your IP and port data should be specified, just like in the command line example.You must use similar proxy options when working with the command line, depending on what your proxy is. After saving the docker proxy config file, the information you specified will apply to all new containers and to ready-made containers downloaded from the Docker repository.
Want our new articles in your Google results? Add StableProxy as a preferred source.
If your proxies require a username and password, you must include them directly in the proxy URL inside the configuration file or command. The format is: http://username:[email protected]:Port. Note that if the password contains special characters (like @, :, /), they must be URL-encoded.
The configuration specified in ~/.docker/config.json is applied as environment variables only at the moment new containers are created or started. Already running containers cannot dynamically read changes from this file. For them to use the proxy, they must be stopped, removed, and started again.
To allow the Docker daemon itself to pull images (e.g., executing docker pull) through a proxy, user settings in config.json are not enough. You need to configure the proxy for the system service. On Linux systems, this is done by creating a configuration file at /etc/systemd/system/docker.service.d/http-proxy.conf specifying the HTTP_PROXY and HTTPS_PROXY environment variables, and then restarting the service with systemctl restart docker.
Use the noProxy parameter in the configuration file or the --env NO_PROXY="..." argument. In it, specify a comma-separated list of domain names, hosts, or subnets that should be accessed directly. Make sure to include localhost, 127.0.0.1, and your Docker internal network range to avoid breaking container-to-container communication.
Yes. The config.json file sets the default (global) settings for all containers. If you need a specific container to use a different proxy, simply override the environment variables directly during its launch using the -e HTTP_PROXY="..." and -e HTTPS_PROXY="..." flags within the docker run command. Command-line parameters take precedence.
Officially, Docker expects httpProxy and httpsProxy inside config.json. However, many modern tools and base images support the SOCKS5 protocol if specified in the URL scheme: socks5://proxy.example.com:Port or socks5h://... (to resolve DNS through the proxy). If a specific software inside the container does not support SOCKS, you will need to use third-party tools to convert traffic (e.g., proxychains or privoxy).
StableProxy
© StableProxy – 2021 - 2026 – Ukraine
