Dockerfile fails to build

Viewed 6460

Till few days back the Dockerfile was working fine and when i tried to build it again today it is giving following error in the terminal. I tried with multiple docker base images but still giving the same error. Can any one help me with this? I dont think i missed out anything. If i had missed it should have given me the error earlier itself but why now?

Err:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
  Temporary failure resolving 'security.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu xenial InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package software-properties-common    

and my docker version is Docker version 17.03.2-ce, build f5ec1e2


And here is my Dockerfile

FROM ubuntu:16.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update -y && \
    apt-get install -y software-properties-common && \
    apt-add-repository ppa:webupd8team/java && \
    apt-get update -y && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \
    echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java8-installer && \
    apt-get install -y oracle-java8-unlimited-jce-policy && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /var/cache/oracle-jdk8-installer

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle
7 Answers

Solution that worked for me was to

  1. check my host machine /etc/resolv.conf - looking for nameserver x.x.x.x

  2. copy the nameserver that was there into my host machine's /etc/docker/daemon.json

    • this may require you to sudo su in order cd /etc/docker
    • you may not have that file, so just created it: nano daemon.json
    • add the following:
{
    "dns": ["x.x.x.x", "z.z.z.z", "8.8.8.8"]
}

x.x.x.x and z.z.z.z could be your nameservers 8.8.8.8 is google's, which you can try.

  1. Need to restart the docker daemon - sudo service docker restart

Over time my nameserver (at my house) changed, so I have a few, or I have to add to this file every now and then. It could also change if you are using the internet in different places - so this is not always the best solution.

In my case bridge network was disabled in daemon.json.

After fixing as below it worked.

root@pc:/etc/docker# cat daemon.json
{
    "iptables": true,
    "bridge": "docker0"
}

And dont forget to restart:

sudo service docker restart

Also I used following useful commands to investigate the issue:

# List networks (it should have 3 lines bridge, host, none)
docker network ls

# Check the logs, it will have docker log
journalctl -xe

# This one showed me at the end that bridge was missing iptables config like below
# WARNING: bridge-nf-call-iptables is disabled
# WARNING: bridge-nf-call-ip6tables is disabled
docker info
Related