Настраиваем прокси сервер на платформе Docker
Настройка прокси сервера может потребоваться на платформе Docker в ряде случаев. Самыми распространёнными являются обход лимитов веб-провайдера и проведение тестов разработанного вами ПО во многих геолокациях. Начнём с рассмотрения понятия Докера.
Олександр Л.
11 June 2025
920
920
11 June 2025
What Is Docker
Docker is a suite of products implemented on the "platform as a service" (PaaS) principle, utilizing OS-level virtualization to deliver software in packages called containers, that is, to perform containerization of packages. The service offers different payment tiers: free and premium with extended features. This software was released in 2013. In other words, Docker is a platform for developing, delivering, and running applications, where you can separate your software from your infrastructure. Thus, a built container can be run on various operating systems. Additionally, you will be pleased to learn that the Docker platform supports SSL, providing excellent data and network security, especially when testing applications. Containerized information includes:
- The software itself that needs to be run by the developer;
- The runtime environment — a virtual machine with the minimal necessary processes;
- Files required for running the software;
- Server.
Setting Up a Proxy in Docker
There are 2 ways to configure it: via the command line and using a config file. The command line procedure looks like this:
- Since you will use the parameter proxy.example.com:Port, you need to find out the IP address of your proxy and the port being used.
- In the command line, write the command
docker build, which creates the config. You need to use the--build-argargument. 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 runcommand to start the created config. It is necessary to use the--envargument. The full command will look like this:docker run --env HTTP_PROXY="http://proxy.example.com:Port" redisConfiguring Docker proxy via a config file looks like this: - In your working directory, find the
.dockerfolder. It should contain a file namedconfig.json. Create it if missing. - In the file, using your preferred 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"
}
}
}
- Instead of proxy.example.com:Port, enter your IP address and port details, similarly to the example with the command line.
- In the config file, as shown in the code above, you can use 4 proxy options:
HttpProxy— for HTTP without encryption;HttpsProxy— for HTTPS with encryption;ftpProxy— for FTP for file transfer;noProxy— for directing traffic directly. Similar proxy options should be used when working with the command line, depending on your proxy setup. After saving yourdocker proxyconfig file, the information you entered will be applied to all new containers and to existing containers loaded from the Docker repository.
