Docker compose does not work using proxy

2

I am creating a docker-compose file to upload a multi-node system. To start testing, I created only one service in this 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 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

As I use a corporate proxy, I researched how to tell you how to build this image, and I checked that this would be possible with 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 proxy on the 3128 port, without authentication required. The problem is that when I try to run the build, an error occurs because of this proxy configuration:

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 configure the proxy for the build of this image in docker-compose ? I've tried several tutorials, but I did not succeed.

- Machine: Ubuntu 18 - Docker version 18.06.1-ce - docker-compose version 1.15.0, build e12f3b9

    
asked by anonymous 01.10.2018 / 17:39

1 answer

2

I was able to resolve by setting the Docker client [1] :

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

Follow here for all the steps needed 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
    
01.10.2018 / 22:32