DEV Community

Setup the proxy for Dockerfile building

Peter on March 01, 2018

If we just need to pull or push the docker image, it is fine to set up the proxy by system service conf file. But this proxy setting seems don't wo...
Collapse
 
dcruz1990 profile image
Dennis Quesada Cruz

Didn't work in my laptop :(

```$ sudo docker build --build-arg http_proxy=192.168.100.4:3128/ --build-arg https_proxy=192.168.100.4:3128/ -t thibaut/devdocs .
Sending build context to Docker daemon 18.3MB
Step 1/10 : FROM ruby:2.6.0
Get registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)


Collapse
 
activeliang profile image
activeliang

it work for me, thx~

Collapse
 
pyoy profile image
pyn

The proxy configuration did not take effect, so I hope we can discuss this issue.
I found that the build was connected to the nearest acceleration address in the /etc/docker/daemon.json configuration, and even after removing the daemon.json file, the proxy configuration of the build still did not take effect, and it was directly connected to the official address without accessing it through a proxy, which itself is reliable, and even switched to a LAN proxy to ensure its reliability;

The proxy configuration, whether configured in docker-compose.yml or in Dockerfile, did not take effect.

My environment I:
AlmaLinux release 8.7 (Stone Smilodon) 4.18.0-425.3.1.el8.x86_64
Docker 24.0.2
Docker Compose version v2.18.1

My environment II:
CentOS Linux release 7.9.2009 (Core) 3.10.0-1160.el7.x86_64
Docker Version: 23.0.1
docker-compose version 1.29.2

The configuration is the same for both environments:
docker-compose.yml agent configuration:

version: "2.7"
services.
  nginx.
    build.
      context: . /nginx
      dockerfile: . /nginx_Dockerfile
      args.
        - http_proxy="http://192.168.130.78:8080"
        - https_proxy="http://192.168.130.78:8080"
    container_name: "nginx"
......
Enter fullscreen mode Exit fullscreen mode

Dockerfile proxy configuration:

cat nginx/nginx_Dockerfile 
FROM nginx:1.23.1
ENV http_proxy http://192.168.130.78:8080
ENV https_proxy http://192.168.130.78:8080
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lixiton profile image
jack

works for me.
As a reminder: point the proxy server to your linux machine's ip. Don't use localhost because localhost refer to your docker and docker run in an isolated network. Obviously, you don't have a proxy server in it.

Collapse
 
alexandrett profile image
Alexandre

I do agreed!!!! This is clearly a bad practice to use ENV to declare a proxy: docs.docker.com/network/proxy/#pro...
Your image becomes dependent from environment, your dockerfile could contain sensitive data...

Collapse
 
santizo profile image
santizo

Thanks.

Collapse
 
indykpol profile image
indykpol

Thanks Peter, this actually worked for me.

Collapse
 
rajitid profile image
rajitid

great.. worked fine.

Collapse
 
davidperezingeniero profile image
David Pérez Carmona

It works! Thanks.