Docker Compose does not work using proxy

Asked

Viewed 983 times

2

I’m creating a file docker-compose to upload a system with multiple nodes. To start testing, I created only one service in that file docker-compose.yml:

version: '3'

networks:
  production-network:
    driver: bridge

services:
  node1:
    build:
      dockerfile: ./docker/alura-books.dockerfile
      context: .
    image: giulianasilvabezerra/alura-books
    container_name: alura-books-1
    ports:
      - "3000"
    networks:
      - production-network

To build my service, I have the Dockerfile below:

FROM node:latest
MAINTAINER Douglas Quintanilha
ENV NODE_ENV=development
COPY . /var/www
WORKDIR /var/www
RUN npm install 
ENTRYPOINT ["npm", "start"]
EXPOSE 3000

Since I use a corporate proxy, I researched how to inform you to build this image, and verified that this would be possible with the npm config. So I added the commands:

RUN npm cache clean -f
RUN npm config set proxy http://10.100.5.107:3128
RUN npm config set https-proxy http://10.100.5.107:3128
RUN npm update
RUN npm install

Ond 10.100.5.107 is the ip of my machine that serves as a proxy on the port 3128, no authentication required. The problem is that when I try to run the build, an error occurs due to this proxy setting:

docker-compose build
Building node1
Step 1/12 : FROM node:latest ---> 8672b25e842c
Step 2/12 : MAINTAINER Douglas Quintanilha ---> Using cache
 ---> 57cc55c8c60a
Step 3/12 : ENV NODE_ENV=development
 ---> Using cache
 ---> ad9c7e8d30c1
Step 4/12 : COPY . /var/www
 ---> aec64fdc16ae
Step 5/12 : WORKDIR /var/www
 ---> Running in d1121964dbe4
Removing intermediate container d1121964dbe4
 ---> 78f225a89e7d
Step 6/12 : RUN npm cache clean -f
 ---> Running in f84cd3c05903
npm WARN using --force I sure hope you know what you are doing.
Removing intermediate container f84cd3c05903
 ---> ec8d4392504e
Step 7/12 : RUN npm config set proxy http://localhost:3128
 ---> Running in 1d9af892155c
Removing intermediate container 1d9af892155c
 ---> 71813002714c
Step 8/12 : RUN npm config set https-proxy http://localhost:3128
 ---> Running in 3d9376ff8574
Removing intermediate container 3d9376ff8574 ---> a74660004639
Step 9/12 : RUN npm update
 ---> Running in 1af0de20e9e2
npm ERR! code ECONNRESET
npm ERR! network tunneling socket could not be established, cause=connect ECONNREFUSED 127.0
.0.1:3128
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-10-01T15_32_58_226Z-debug.log
ERROR: Service 'node1' failed to build: The command '/bin/sh -c npm update' returned a non-z
ero code: 1

How should I set up the proxy to build this image on docker-compose? I have searched in several tutorials, but I did not succeed.

OBS: - Machine: Ubuntu 18 - Docker version 18.06.1-ce - Docker-Compose version 1.15.0, build e12f3b9

  • 1

    Hello, take a look at this link, maybe the option to set as an environment variable ENV HTTP_PROXY "http://127.0.0.1:3001" work.

  • I have tried this, but only the environment variable is not enough to configure NPM. When I set it up also with npm config keeps giving connection error. Although, when I drop to proxy address it works.

1 answer

3


I was able to solve by configuring the Docker client [1]:

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://10.100.5.107:3128",
     "noProxy": "*.test.example.com,.example2.com"
   }
 }
}

Follow here, for interested, all the necessary steps to configure Docker on Ubuntu with the proxy:

## Removendo versões antigas
sudo apt-get remove docker docker-engine docker.io
sudo apt-get update
## Adicionando a chave GPG oficial do Docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
## Adicionando repo do Docker no APT
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
## Instala o Docker
sudo apt-get install docker-ce
## Executar Docker sem sudo
sudo usermod -aG docker $(whoami)
## Configurar proxy
sudo mkdir -p /etc/systemd/system/docker.service.d
echo "[Service]
Environment=\"HTTP_PROXY=http://127.0.0.1:3128\"" > /etc/systemd/system/docker.service.d/http-proxy.conf
## Reunicia o docker pra carregar o proxy
sudo systemctl daemon-reload
sudo systemctl restart docker

## Instala o Docker compose
sudo curl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

## Adicionar o proxy no docker client
mkdir ~/.docker/
echo "{
 \"proxies\":
 {
   \"default\":
   {
     \"httpProxy\": \"http://127.0.0.1:3128\",
     \"noProxy\": \"*.test.example.com,.example2.com\"
   }
 }
}" > ~/.docker/config.json

Browser other questions tagged

You are not signed in. Login or sign up in order to post.