0

I'm trying to create an apache + php docker container, but I am getting a build error.

Here's my dockerfile,

FROM ubuntu:14.04

MAINTAINER Mizanur Rahman 

RUN apt-get update
RUN apt-get -y upgrade

RUN apt-get install -y apache2 libapache2-mod-php5 php5-mysql php5-gd php-pear php-apc php5-curl curl lynx-cur php5-intl

RUN a2enmod php5
RUN a2enmod rewrite

RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php5/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php5/apache2/php.ini

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

# Copy site into place.
ADD www /var/www/site

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

# By default, simply start apache.
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

Here's the build output,

Sending build context to Docker daemon 44.23 MB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
 ---> fa81ed084842
Step 1 : MAINTAINER Mizanur Rahman <getmizanur@gmail.com>
 ---> Using cache
 ---> 4c5dfddabbc7
Step 2 : RUN apt-get update
 ---> Running in 938037477c9c
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Err http://archive.ubuntu.com trusty Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security Release.gpg
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Ign http://archive.ubuntu.com trusty Release
Ign http://archive.ubuntu.com trusty-updates Release
Ign http://archive.ubuntu.com trusty-security Release
Ign http://archive.ubuntu.com trusty/main amd64 Packages/DiffIndex
Ign http://archive.ubuntu.com trusty/restricted amd64 Packages/DiffIndex
Err http://archive.ubuntu.com trusty/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-updates/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/main Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/restricted Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/universe Sources
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty-security/universe amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/main amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
Err http://archive.ubuntu.com trusty/restricted amd64 Packages
  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/main/source/Sources  Something wicked happened resolving 'archive.ubuntu.com:http' (-5 - No address associated with hostname)

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/t

And finally, here's the error message

The command [/bin/sh -c apt-get update] returned a non-zero code: 100

I have tried few solutions to resolve this issue , and none of them are working for me.

For example,

Docker containers can't resolve DNS on Ubuntu 14.04 Desktop Host

The command [/bin/sh -c apt-get update] returned a non-zero code: 100

Can anyone help me with this? Thanks in advance.

getmizanur
  • 593
  • 1
  • 5
  • 13
  • Avoid `apt-get upgrade` in Dockerfiles, see [best practises](https://docs.docker.com/articles/dockerfile_best-practices/). – OrangeTux Jun 13 '15 at 10:25
  • This points to a networking issue inside the container. Rather than looking at the apt output, we'd need to see the debugging of the networking stack, things like route tables, firewall rules, traceroute, a description of your local network, etc. – BMitch Jul 27 '22 at 13:43

3 Answers3

0

I am on Ubuntu image and the thing which I had to add to Docker file before apt-get update was:

RUN echo Acquire::http::Proxy \"user:pass@proxy.com:port/\"\; >> /etc/apt/apt.conf.d/proxy.conf

This: https://docs.docker.com/config/daemon/systemd/ and this was not enough for apt-get to work:

ENV HTTP_PROXY="http://user:pass@proxy.com:port"

mdev111
  • 1
  • 1
0

You are getting the following errors...

No address associated with hostname

Something wicked happened resolving

The main reason could be that the system's DNS settings are misconfigured.

How can we solve ?

First check if the resolv.conf file is available in in the directory /etc

( This is usually the main install location for the resolv.conf file )

You can check its existence with the commands below...

ls + wc = para returns existence with 0 or 1

0 for does not exist is 1 for exists.

ls /etc | grep resolv.conf | wc -l

ls = find resolv.conf not found will return

ls: cannot access '/etc/resolv.conf': No such file or directory.

ls /etc/resolv.conf

If the file is not available, you will need to configure a dns resolver. For this, we will use resolv.conf.

Install resolv.conf packages

apt-get install resolveconf

systemctl enable resolvconf.service

Open the /etc/resolv.conf file with any text editor like nano towards add your dns records of your choice like Google CloudFlare Quad9 OpenDns Resolv.conf accepts up to 3 different nameserver.

search mylinux localhost

nameserver 8.8.8.8

nameserver 8.8.4.4

A more versatile way if you don't want to access the /etc/resolv.conf file with your editor is to apply the commands with echo through the terminal.

echo "search mylinux localhost" > /etc/resolv.conf

echo "nameserver 8.8.8.8 " > /etc/resolv.conf

echo "nameserver 8.8.4.4 " > /etc/resolv.conf

Be careful with >> at the end of your echo may wipe your entire file and leave your system with no local resolver.

Done save with ctrl X + Y

Now let's create a reference hostname if your system doesn't have these variables.

Access the /etc/hosts file with your preferred editor like nano and add the values.

127.0.1.1 is often used for the machine's FQDN

127.0.1.1 myLinux

The following lines are desirable for IPv4 capable hosts

127.0.0.1 localhost

The following lines are desirable for IPv6 capable hosts

::1 localhost ip6-localhost ip6-loopback

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

Done save with ctrl X + Y

Let's add dns variable in our nsswitch.conf

Access the /etc/nsswitch.conf file with your preferred editor like nano:

Before

networks: files

Now

networks: files dns

Done save with ctrl X + Y

Now add in /etc/host.conf an extra for your hostname (read the host.conf manual)

Access the /etc/host.conf file with your preferred editor like nano:

Adicione the text below if it doesn't exist

order hosts, multi on

Done save with ctrl X + Y

Now everything now we can activate our resolv.conf execute

START

systemctl start resolvconf.service

STATUS

systemctl status resolvconf.service

let's go to the tests...

ping to 8.8.8.8

ping 8.8.8.8

If everything went well the result will be:

PING 8.8.8.8 ( 8.8.8.8 ) 56(84) bytes of data. 64 bytes from 8.8.8.8 : icmp_seq=1 ttl=59 time=12.0 ms 64 bytes from 8.8.8.8 : icmp_seq=2 ttl=59 time=12.1 ms

Don't forget to check your apt-get

a short bug fix...

apt-get --fix-broken upgrade

apt-get --fix-broken install

apt-get check

a quick cleaning...

apt-get autoremove

apt-get autoclean

We're done here...

Go further if the problem persists...

Analyzing your sources.list listing Ubuntu 14.04.6 LTS (Trusty Tahr) as your operating system.

In some cases, the sources.list as configured during installation may have been broken, preventing you from using apt-get on your system (depending on how this image was built). One tip is to review your sources.list and comment out the faulty URL with #

Quick access using apt-get to the path /etc/apt/sources.list

apt edit-sources

Finally, if the problem continues, try formatting your system and start again installing your docker from scratch.

Luana
  • 19
  • 5
-1

Your problem is related to firewall settings. Execute as root user:

sudo iptables -L -n -v

to list all firewall rules and check FORWARD chain POLICY. It has to be set to to ACCEPT for Docker DNS resolution to work properly.

If it's set to DROP or REJECT, then execute:

sudo ufw disable

If you don't have ufw installed, then execute:

sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT
Tomasz Klim
  • 458
  • 5
  • 10
  • Entirely disabling the firewall seems like an unnecessarily heavy-handed way to deal with this... – BE77Y Jun 08 '15 at 15:46
  • Entirely disabling the firewall is the only way to be 100% sure, if the problem is caused by the firewall or not. After that, indeed it would be wise to enable firewall again and just fix its rules. But only in that order. – Tomasz Klim Jun 09 '15 at 13:27
  • It's not the only way - but regardless, you did not make clear in your answer that doing so would merely be temporary, and that it would be crucial to re-enable the firewall after the test. – BE77Y Jun 09 '15 at 13:31
  • Because it's obvious and mentioned in several texts about Docker. Good answer shouldn't repeat advices from manuals. Instead it should be clear, short and let the author go straight to the problem. – Tomasz Klim Jun 09 '15 at 13:40
  • Many good answers repeat text from manuals verbatim, as a matter of fact - and "obviousness" is subjective. Leaving crucial information out makes for a poor answer. – BE77Y Jun 09 '15 at 13:44