Dockerfile not able to connect proxy server

Viewed 160

I have a docker file to get packages from a remote repository when I'm running a docker file inside my Linux VM docker file creating docker images without any issue.

Same Docker file when I'm calling from Jenkins pipeline getting failed to unable to reach the network.

cat Dockerfile
FROM docker-registry-remote.artifactory.myrepo.com/node
ADD myapp /usr/src/app/myapp
ENV http_proxy=http://10.1.2.3:8080/
ENV https_proxy=http://10.1.2.3:8080/
RUN apt-get update

Jenkins build log Err:9 http://deb.debian.org/debian stretch/main amd64 Packages Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)

ping test from jenkins vm

[root@ip-10-1-1-1 tmp]# ping 10.1.2.3
PING 10.1.2.3 (10.1.2.3) 56(84) bytes of data.
64 bytes from 10.1.2.3: icmp_seq=1 ttl=247 time=22.9 ms
64 bytes from 10.1.2.3: icmp_seq=2 ttl=247 time=22.5 ms
64 bytes from 10.1.2.3: icmp_seq=3 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=4 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=5 ttl=247 time=22.3 ms
64 bytes from 10.1.2.3: icmp_seq=6 ttl=247 time=22.4 ms
^C
--- 10.1.2.3 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5002ms
rtt min/avg/max/mdev = 22.357/22.531/22.968/0.211 ms

build docker image from jenkins vm

Ign:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Err:9 http://deb.debian.org/debian stretch/main amd64 Packages
  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
Ign:10 http://deb.debian.org/debian stretch/main all Packages
Err:11 http://deb.debian.org/debian stretch-updates/main amd64 Packages
  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
Ign:12 http://deb.debian.org/debian stretch-updates/main all Packages
Reading package lists...
W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages  Cannot initiate the connection to 10.1.2.3:8080 (10.1.2.3). - connect (101: Network is unreachable)

1 Answers

I resolved above issue using --network host option while building my docker images.

docker build -f Dockerfile --network host --no-cache -t mytag .
Related