无法可靠地确定服务器的完全限定域名......如何在Docker中解决它? [英] Could not reliably determine the server's fully qualified domain name ... How to solve it in Docker?

查看:30
本文介绍了无法可靠地确定服务器的完全限定域名......如何在Docker中解决它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Docker,我正在关注教程,它基本上显示了这些步骤:

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

  1. 像这样创建一个 Dockerfile:

  1. Create a Dockerfile like this:

来自 php:7.0-apache复制 src//var/www/html暴露 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 式)解决警告消息的方法.但首先,在盲目设置 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 运行参考文档,https://docs.docker.com/engine/reference/run/#managing-etchosts.它提到:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆