title: Docker build fails to fetch packages from archive.ubuntu.com inside bash script used in Dockerfile
body: <p>Trying to build a docker image with the execution of a pre-requisites installation script inside the Dockerfile fails for fetching packages via apt-get from <a href="http://archive.ubuntu.com/" rel="nofollow noreferrer">archive.ubuntu.com</a>.</p>
  <p>Using the <code>apt-get</code> command inside the Dockerfile works flawless, despite being behind a corporate proxy, which is setup via the <code>ENV</code> command in the Dockerfile.
  Anyway, executing the <code>apt-get</code> command from a bash-script in a terminal inside the resulting docker container or as &quot;postCreateCommand&quot; in a devcontainer.json of Visual Studio Code does work as expected too. But it won't work in my case for the invocation of a bash script from inside a Dockerfile.
  It simply will tell:</p>
  <pre class="lang-sh prettyprint-override"><code>Starting installation of package iproute2
  Reading package lists...
  Building dependency tree...
  The following additional packages will be installed:
  libatm1 libcap2 libcap2-bin libmnl0 libpam-cap libxtables12
  Suggested packages:
  iproute2-doc
  The following NEW packages will be installed:
  iproute2 libatm1 libcap2 libcap2-bin libmnl0 libpam-cap libxtables12
  0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
  Need to get 971 kB of archives.
  After this operation, 3,287 kB of additional disk space will be used.
  Err:1 http://archive.ubuntu.com/ubuntu focal/main amd64 libcap2 amd64 1:2.32-1
  Could not resolve 'archive.ubuntu.com'
  
  ... more output ...
  
  E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libc/libcap2/libcap2_2.32-1_amd64.deb  Could not resolve 'archive.ubuntu.com'
  
  ... more output ...
  </code></pre>
  <p>Just for example a snippet of the Dockerfile looks like this:</p>
  <pre class="lang-sh prettyprint-override"><code>FROM ubuntu:20.04 as builderImage
  
  USER root
  
  ARG HTTP_PROXY_HOST_IP='http://172.17.0.1'
  ARG HTTP_PROXY_HOST_PORT='3128'
  ARG HTTP_PROXY_HOST_ADDR=$HTTP_PROXY_HOST_IP':'$HTTP_PROXY_HOST_PORT
  
  ENV http_proxy=$HTTP_PROXY_HOST_ADDR
  ENV https_proxy=$http_proxy
  ENV HTTP_PROXY=$http_proxy
  ENV HTTPS_PROXY=$http_proxy
  ENV ftp_proxy=$http_proxy
  ENV FTP_PROXY=$http_proxy
  
  # it is always helpful sorting packages alpha-numerically to keep the overview ;)
  RUN apt-get update &amp;&amp; \
      apt-get -y upgrade &amp;&amp; \
      apt-get -y install --no-install-recommends apt-utils dialog 2&gt;&amp;1 \
      &amp;&amp; \
      apt-get -y install \
          default-jdk \
          git \
          python3 python3-pip
  
  SHELL [&quot;/bin/bash&quot;, &quot;-c&quot;]
  
  ADD ./env-setup.sh .
  RUN chmod +x env-setup.sh &amp;&amp; ./env-setup.sh
  
  CMD [&quot;bash&quot;]
  </code></pre>
  <p>The minimal version of the environment script <code>env-setup.sh</code>, which is supposed to be invoked by the Dockerfile, would look like this:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  packageCommand=&quot;apt-get&quot;;
  sudo $packageCommand update;
  packageInstallCommand=&quot;$packageCommand install&quot;;
  package=&quot;iproute2&quot;
  packageInstallCommand+=&quot; -y&quot;;
  sudo $packageInstallCommand $package;
  </code></pre>
  <p>Of course the usage of variables is down to making use of a list for the packages to be installed and other aspects.</p>
  <p>Hopefully that has covered everything essential to the question:</p>
  <p>Why is the execution of <code>apt-get</code> working with a <code>RUN</code> and as well running the bash script inside the container after creating, but not from the very same bash script while building the image from a Dockerfile?</p>
  <p>I was hoping to find the answer with the help of an extensive web-search, but unfortunately I was only able to find anything but an answer to this case.</p>