Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not reliably determine the server's fully qualified domain name ... How to solve it in Docker?

Tags:

docker

apache

I am just starting in Docker and I was following that tutorial that shows basically these steps:

  1. Create a Dockerfile like this:

    From php:7.0-apache copy src/ /var/www/html EXPOSE 80 
  2. Build the container from where I have my dockerfile:

    $ docker build -t mytest . 
  3. After the image "mytest" is generated I run it with:

    $ docker run  -p 80 mytest 

That is what I get as error:

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Sun Sep 17 16:25:12.340564 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/7.0.23 configured -- resuming normal operations [Sun Sep 17 16:25:12.340666 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

So, I don't know how to solve it. Any idea?

like image 481
IgorAlves Avatar asked Sep 17 '17 16:09

IgorAlves


People also ask

Could not reliably determine the Server's fully qualified Apache?

An Apache AH00558: Could not reliably determine the server's fully qualified domain name message is generated when Apache is not configured with a global ServerName directive. The message is mainly for informational purposes, and an AH00558 error will not prevent Apache from running correctly.

How do I set the ServerName directive globally in Windows?

The fix for this configuration error is simple: all you have to do is edit your “/etc/apache2/apache2. conf” file, adding a global ServerName directive. Note that this global directive is required to eliminate the error message even if you already have a virtual server configured with its own ServerName directive.

How configure httpd conf?

Apache is configured by placing configuration directives, such as Listen and ServerName , into a configuration file, which will be read by the Apache executable during the startup. The default configuration file is called " httpd. conf " (or " apache2. conf ") in the directory " <APACHE_HOME>\conf ".

Where is httpd conf?

If you installed httpd from source, the default location of the configuration files is /usr/local/apache2/conf . The default configuration file is usually called httpd. conf .


1 Answers

I'd like to offer another (maybe more Docker-ish) way of solving the warning message. But first, it makes sense to understand what Apache is actually doing to figure out the domain name before just blindly setting ServerName. There is a good article at http://ratfactor.com/apache-fqdn.html which explains the process.

Once we can confirm that getnameinfo is what Apache uses to lookup the name and that it uses /etc/nsswitch.conf to determine where to go first for the lookup, we can figure out what to modify.

If we check out the nsswitch.conf inside the container we can see that it looks up hosts in the /etc/hosts file before external DNS:

# cat /etc/nsswitch.conf | grep hosts hosts:          files dns 

Knowing this, maybe we can influence the file at Docker runtime instead of adding it to our configuration files?

If we take a look at the Docker run reference documentation there is a section on the /etc/hosts file at https://docs.docker.com/engine/reference/run/#managing-etchosts. It mentions:

Your container will have lines in /etc/hosts which define the hostname of the container itself as well as localhost and a few other common things.

So, if we just set the container hostname, it will get added to /etc/hosts which will solve the Apache warning. Fortunately, this is very easy to do with the --hostname or -h option. If we set this to a fully qualified domain name, Docker will set it in our /etc/hosts file and Apache will pick it up.

It is pretty easy to try this out. Example with the warning (no hostname):

$ docker run --rm php:7.0-apache AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Sun Sep 17 19:00:32.919074 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/7.0.23 configured -- resuming normal operations [Sun Sep 17 19:00:32.919122 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 

Now with the -h option set to a fully qualified domain name:

$ docker run --rm -h myapp.mydomain.com php:7.0-apache [Sun Sep 17 19:01:27.968915 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/7.0.23 configured -- resuming normal operations [Sun Sep 17 19:01:27.968968 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' 

Hope this helps answer the question and provide some learning about Apache and fully qualified domain names.

like image 98
Andy Shinn Avatar answered Sep 25 '22 01:09

Andy Shinn