无法可靠地确定服务器的标准域名...如何在Docker中解决? [英] Could not reliably determine the server's fully qualified domain name ... How to solve it in Docker?
问题描述
我刚刚开始使用Docker,我一直在关注教程,该教程基本上显示了这些内容步骤:
I am just starting in Docker and I was following that tutorial that shows basically these steps:
-
像这样创建一个Dockerfile:
Create a Dockerfile like this:
From php:7.0-apache
copy src/ /var/www/html
EXPOSE 80
From php:7.0-apache
copy src/ /var/www/html
EXPOSE 80
从我拥有dockerfile的位置构建容器:
Build the container from where I have my dockerfile:
$ docker build -t mytest .
生成图像"mytest"后,我使用以下命令运行它:
After the image "mytest" is generated I run it with:
$ docker run -p 80 mytest
这就是我得到的错误:
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 dont know how to solve it. Any help?
推荐答案
我想提供另一种(可能更多的Docker-ish)解决警告消息的方法.但是首先,在盲目地设置ServerName
之前,先了解 Apache实际上正在弄清楚域名的意义. http://ratfactor.com/apache-fqdn.html 上有一篇很好的文章,其中解释了过程.
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.
一旦我们可以确认getnameinfo
是Apache用于查找名称的对象,并且可以使用/etc/nsswitch.conf
确定首先查找的位置,我们就可以找出要修改的内容.
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.
如果我们检查容器内的nsswitch.conf
,我们可以看到它在外部DNS之前的/etc/hosts
文件中查找主机:
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
知道了这一点,也许我们可以在Docker运行时影响文件,而不是将其添加到我们的配置文件中?
Knowing this, maybe we can influence the file at Docker runtime instead of adding it to our configuration files?
如果我们查看Docker运行参考文档,则/etc/hosts
文件上的
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:
您的容器将在/etc/hosts中包含几行,这些行定义了容器本身的主机名以及localhost和其他一些常见的东西.
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.
因此,如果我们仅设置容器主机名,它将被添加到/etc/hosts
中,这将解决Apache警告.幸运的是,使用--hostname
或-h
选项很容易做到这一点.如果我们将其设置为完全限定的域名,则Docker将在我们的/etc/hosts
文件中对其进行设置,而Apache将对其进行提取.
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'
现在将-h
选项设置为完全限定的域名:
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'
希望这有助于回答问题,并提供有关Apache和完全限定域名的一些知识.
Hope this helps answer the question and provide some learning about Apache and fully qualified domain names.
这篇关于无法可靠地确定服务器的标准域名...如何在Docker中解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!