Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile fails to build

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
like image 967
Prateek Naik Avatar asked Jun 30 '17 08:06

Prateek Naik


3 Answers

If your host is an Ubuntu VM, it could be an invalid /etc/resolve.conf. Look at the /etc/resolv.conf on the host Ubuntu VM. If it contains nameserver 127.0.1.1, that is wrong.

Run these commands on the host Ubuntu VM to fix it:

sudo vi /etc/NetworkManager/NetworkManager.conf
# Comment out the line `dns=dnsmasq` with a `#`

# restart the network manager service
sudo systemctl restart network-manager

cat /etc/resolv.conf

Now /etc/resolv.conf should have a valid value for nameserver, which will be copied by the docker containers.

like image 110
wisbucky Avatar answered Oct 11 '22 06:10

wisbucky


Looks like you have a connection error in your RUN instruction.

Try doing the same commands in an Ubuntu Container.
docker run -it ubuntu bash

And then inside the container do your RUN command.

On my machine, your script does work.

like image 32
Wassim Dhif Avatar answered Oct 11 '22 06:10

Wassim Dhif


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.

like image 3
amurrell Avatar answered Oct 11 '22 06:10

amurrell