Docker Community Forums

Share and learn in the Docker community.

Proxy Issues with docker build?

Hello,

Docker Guest OS:

root@srv-lx-k8s-worker-01:~/Dockerfiles# cat /etc/issue
Ubuntu 18.04.4 LTS \n \l

Docker Version:

root@srv-lx-k8s-worker-01:~/Dockerfiles# docker version
Client:
 Version:           18.09.7
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        2d0083d
 Built:             Thu Jun 27 17:56:23 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.7
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       2d0083d
  Built:            Thu Jun 27 17:23:02 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Just doing a basic docker build.

Here’s my Dockerfile3:

root@srv-lx-k8s-worker-01:~/Dockerfiles# cat Dockerfile3 
from    dadiaspe-custom-image-2
run     apt-get -y update
run     apt-get install nano

Here’s the command I’m executing:

root@srv-lx-k8s-worker-01:~/Dockerfiles# docker build -t dadiaspe-custom-image-3 -f Dockerfile3 .
Sending build context to Docker daemon  3.072kB
Step 1/3 : from dadiaspe-custom-image-2
 ---> 57af988bf58a
Step 2/3 : run  apt-get -y update
 ---> Running in 56d1a97deb30
Ign http://archive.ubuntu.com trusty InRelease
Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Hit http://archive.ubuntu.com trusty Release.gpg
Get:3 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1460 kB]
.
.
.
Ign https://esm.ubuntu.com trusty-infra-updates Release.gpg
Ign https://esm.ubuntu.com trusty-infra-security Release
Ign https://esm.ubuntu.com trusty-infra-updates Release
Err https://esm.ubuntu.com trusty-infra-security/main amd64 Packages
  Failed to connect to esm.ubuntu.com port 443: Connection timed out
Err https://esm.ubuntu.com trusty-infra-updates/main amd64 Packages
  Failed to connect to esm.ubuntu.com port 443: Connection timed out
Fetched 13.4 MB in 30min 2s (7425 B/s)
W: Failed to fetch https://esm.ubuntu.com/ubuntu/dists/trusty-infra-security/main/binary-amd64/Packages  Failed to connect to esm.ubuntu.com port 443: Connection timed out

W: Failed to fetch https://esm.ubuntu.com/ubuntu/dists/trusty-infra-updates/main/binary-amd64/Packages  Failed to connect to esm.ubuntu.com port 443: Connection timed out

E: Some index files failed to download. They have been ignored, or old ones used instead.
The command '/bin/sh -c apt-get -y update' returned a non-zero code: 100

If I run apt-get update -y from the Guest OS command line, no issues:

root@srv-lx-k8s-worker-01:~/Dockerfiles# apt-get -y update
Hit:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 https://download.docker.com/linux/ubuntu bionic InRelease                                      
Get:3 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Fetched 252 kB in 1s (316 kB/s)     
Reading package lists... Done
root@srv-lx-k8s-worker-01:~/Dockerfiles# 

I’m behind a proxy. Here’s my settings for Proxy:

root@srv-lx-k8s-worker-01:~/Dockerfiles# cat /etc/profile.d/proxy.sh
# set proxy config via profie.d - should apply for all users
# 
export http_proxy="http://192.168.1.35:3128/"
export https_proxy="http://192.168.1.35:3128/"
export ftp_proxy="http://192.168.1.35:3128/"
export no_proxy="127.0.0.1,localhost"

# For curl
export HTTP_PROXY="http://192.168.1.35:3128/"
export HTTPS_PROXY="http://192.168.1.35:3128/"
export FTP_PROXY="http://192.168.1.35:3128/"
export NO_PROXY="127.0.0.1,localhost"

Any ideas?

I usaly add --build-arg http_proxy=${http_proxy} to my docker build command, so whenever a system uses a proxy, it will be used to build the image as well. If no proxy is present, it will set the variable to “”, which bypasses the proxy.

Start with --build-arg http_proxy and add furher proxy related variables if required.

1 Like

Yep, bingo, works like a champ!

docker build --build-arg http_proxy=http://192.168.1.35:3128 -t dadiaspe-custom-image-6 -f Dockerfile5 .

Thanks so much @meyay

Welcome!

If you do use a script to perform your builds, you should consider to use http_proxy=${http_proxy} (litteraly!) instead of typing the value, as this will work on machines where http_proxy is set, as well on machines where it’s not set.