Not able to create a base image due to Error connect (101: Network is unreachable)

Not able to create a base image due to Error connect (101: Network is unreachable)

book

Article ID: KB0080124

calendar_today

Updated On:

Products Versions
TIBCO BusinessWorks Container Edition -

Description

While creating a BWCE base image, below error is thrown

++++++++++++++++++
Err http://security.debian.org jessie/updates InRelease

Err http://security.debian.org jessie/updates Release.gpg
  Cannot initiate the connection to security.debian.org:80 (2001:a78:5:1:216:35ff:fe7f:6ceb). - connect (101: Network is unreachable) [IP: 2001:a78:5:1:216:35ff:fe7f:6ceb 80]
+++++++++++++++++

Issue/Introduction

Not able to create a base image due to Error connect (101: Network is unreachable)

Environment

Linux

Resolution

  This issue might occur if there is a http_proxy available on the HOST machine. Even if you set the proxy before running the "docker build" command, the error will be still present.

The issue occurs due to the below reason:
++++++++++++++
Each step in a Dockerfile is executed in a new container. When running RUN export foo=bar, that variable is only present during that step, but no longer there in the next step (container)
++++++++++++++

Solution-1: 
For docker build, you can use --build-arg, which sets environment variables in the container during build only, so they do not remain in the image after build. And there's no need to change your Dockerfile for http_proxy variables, as they are supported by default

For example

docker build --build-arg http_proxy=<ip>:<port> --build-arg http_proxy=<ip>:<port> -t image_name .

Note: If there is also a ftl_proxy then you can add another --build-arg for that.

useful link: https://github.com/moby/moby/issues/20394

Solution-2
Another solution to this issue is to add these proxy lines in the HOST machine's /etc/environment file and then reboot the machine.

Useful link: http://linuxexperimentation.blogspot.com/2011/12/setting-up-proxy-in-kubuntu.html