Search code examples
dockerdockerfiledocker-build

Docker: build with different results compared to manual step-by-step build


I'm trying to build a docker image with a simple Dockerfile:

FROM ubuntu:16.04

RUN echo '91.189.88.161   archive.ubuntu.com' >> /etc/hosts;
RUN echo '91.189.88.162   security.ubuntu.com' >> /etc/hosts;
RUN apt-get update
RUN apt-get install -y git-core python-pip xvfb wkhtmltopdf python-setuptools python-dev build-essential imagemagick libjpeg-dev locales libpq-dev postgresql-client
RUN pip install -r /home/user/requirements/homologacao.txt

CMD /bin/bash

but it does not work. After a few seconds it throws some errors in the 3rd step (apt-get update):

Temporary failure resolving 'archive.ubuntu.com'

However ... if I manually create and attach to a container, using the following command

docker run -it ubuntu:16.04

And then run each command individually, it works like a charm! Can anyone explain to me why does this build do not work, and manually running the commands does? It looks like as each layer/command is not having any effect at all.

What should I do to get this automatic build working? I've changed /etc/default/docker to include the docker network interface in the DNS list:

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4 --dns 172.17.0.1"

Some other info that may be help: Running in an ubuntu 16.04 host, and this issue doesn't happen inside a VM (also ubuntu 16.04) in the same machine. Inside the VM, the apt-get update works right out of the box without having to update /etc/hosts.


Solution

  • I've just tried your Dockerfile and apt-get update worked perfectly.

    Try the following steps:

    1. Create or edit /etc/docker/daemon.json

    2. Add the following content

    {
      "dns": ["8.8.8.8", "8.8.4.4"]
    }
    
    1. Restart Docker daemon: sudo service docker restart

    Edit: Try this.

    FROM ubuntu:16.04
    
    RUN echo '91.189.88.161   archive.ubuntu.com' >> /etc/hosts && \
        echo '91.189.88.162   security.ubuntu.com' >> /etc/hosts && \
        apt-get update && \
        apt-get install -y git-core python-pip xvfb wkhtmltopdf python-setuptools python-dev build-essential imagemagick libjpeg-dev locales libpq-dev postgresql-client
    
    RUN pip install -r /home/user/requirements/homologacao.txt
    
    CMD /bin/bash