Setting up a Proxy Server on the Docker Platform
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.
Олександр Л.
12 June 2025
2637
2637
12 June 2025
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.
What Docker is
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:
- The software itself, the launch of which is required by the developer;
- The runtime environment — a virtual machine with a set of minimally necessary processes;
- Files required to run the software;
- Server.
Configuring a Proxy in Docker
There are 2 ways to configure it: via the command line and using a config file. Working in the command line looks like this:
- Since you will be using the
proxy.example.com:Portparameter, you need to find out the IP address of your proxy and the port used. - In the command line, write the
docker buildcommand, which creates the config. It is necessary to use the--build-argargument in it. The full command will look like this: Bashdocker build --build-arg HTTP_PROXY="http://proxy.example.com:Port" . - Then, in the same command line, enter the
docker runcommand to launch the created config. It is necessary to use the--envargument. 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:
- In the working directory, find the
.dockerfolder. It should contain a file namedconfig.json. Create it if it is missing. - In the file, using your favorite code editor, enter the lines:
JSON
{ "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" } } } - In place of
proxy.example.com:Port, your IP and port data should be specified, just like in the command line example. - In the config file, as seen from the code above, you can use 4 proxy options:
- HttpProxy — for the http option with no encryption;
- HttpsProxy — for the https option with existing encryption;
- ftpProxy — for the ftp option to transfer files using ftp;
- noProxy — for routing direct traffic.
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.
