Настраиваем прокси сервер на платформе Docker
Настройка прокси сервера может потребоваться на платформе Docker в ряде случаев. Самыми распространёнными являются обход лимитов веб-провайдера и проведение тестов разработанного вами ПО во многих геолокациях. Начнём с рассмотрения понятия Докера.
Олександр Л.
12 June 2025
2257
2257
12 June 2025
What is Docker
Docker is a set of products implemented on the principle of "platform as a service" (PaaS), which utilize OS-level virtualization to deliver software in packages called containers, that is, to produce containerized packages. The service offers different payment levels: free and premium with extended 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, a built container can be run on different operating systems. Additionally, you'll be pleased to know that the Docker platform supports SSL, providing excellent levels of information and network security when working with it, particularly during application testing. Containerized information contains:
- The software itself, which needs to be run by the developer;
- Runtime environment — a virtual machine with a set of minimally necessary processes;
- Files required for running the software;
- Server.
Configuring Proxy in Docker
There are 2 ways to set up: via command line and using a config file. Working in the command line looks like this:
- Since you'll use the parameter proxy.example.com:Port, you need to find out the IP address of your proxy and the port used.
- In the command line, write the docker build command, which creates the config. You need to use the --build-arg argument. The full command will look like this:
docker build --build-arg HTTP_PROXY="http://proxy.example.com:Port" - Then, in the same command line, enter the docker run command to start the created config. You need to use the --env argument. The full command will look like this: docker run --env HTTP_PROXY="http://proxy.example.com:Port" redis Configuring Docker Proxy with a config looks like this:
- In your working directory, find the .docker folder. It should contain a file named config.json. Create it if it doesn’t exist.
- In the file, using your favorite code editor, enter the following lines:
{
"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"
}
}
}
- Replace proxy.example.com:Port with your IP address and port, just like in the command line example.
- In the config file, as seen above, you can use four proxy options:
- HttpProxy — for HTTP without encryption;
- HttpsProxy — for HTTPS with encryption;
- ftpProxy — for FTP to transfer files using FTP;
- noProxy — for direct traffic. The same proxy options should be used when working in the command line, depending on your proxy. After saving the config file docker proxy, your provided information will apply to all new containers and to existing containers loaded from the Docker repository.
