Prateek Naik
Prateek Naik

Reputation: 2802

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

Upvotes: 5

Views: 8596

Answers (7)

Khalid Mammadov
Khalid Mammadov

Reputation: 541

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

Upvotes: 1

amurrell
amurrell

Reputation: 2455

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.

Upvotes: 4

Vineet Jain
Vineet Jain

Reputation: 1575

Overview
There are two parts to your question:
1. fixing temporary resolve messages
2. fixing the package management issues

Temporary resolve
It is likely that this issue is either:
1. temporary due to your Internet Service Provider not correctly forwarding internet naming (DNS) to either its or external DNS servers, or
2. due to a change in your network has similarly blocked this naming - for example, new router/modem, reconfiguring a switch with a new configuration.

Let's look at the possible DNS resolving issues.

First, temporarily add a known DNS server to your system.

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null

Then run sudo apt update.

If this fixes your temporary resolving messages then either wait for 24 hours to see if your ISP fixes the issue for you (or just contact your ISP) - or you can permanently add a DNS server to your system:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null

8.8.8.8 is Google's own DNS server.

source

Another example DNS server you could use is OpenDNS- for example:

echo "nameserver 208.67.222.222" | sudo tee /etc/resolvconf/resolv.conf.d/base > /dev/null

package-management issues

In addition to the temporary resolve issues - you have a few package management issues that need to be corrected.
Open a terminal and type:-

sudo nano /etc/apt/sources.list 

and look if you are downloading from right source package.

OR

if you are behind proxy use -E.for example:-
sudo -E apt-get update

Upvotes: 0

chris
chris

Reputation: 2863

A simple method could be write the nslookup archive.ubuntu.com IP to the /etc/hosts, then restart docker.

Of course it needs your docker 's /etc/docker/daemon.json use host machine 's IP.

Upvotes: 0

wisbucky
wisbucky

Reputation: 37973

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.

Upvotes: 4

Prateek Naik
Prateek Naik

Reputation: 2802

I just changed my VM players network setting. Changed Network Connection from bridged mode to NAT. Now its working

Upvotes: 2

Wassim Dhif
Wassim Dhif

Reputation: 1388

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.

Upvotes: 3

Related Questions