当前位置: 首页 > 知识库问答 >
问题:

无法可靠地确定服务器的完全限定域名......如何在Docker中解决?

祁建业
2023-03-14

我刚刚开始学习Docker,我遵循的教程基本上显示了以下步骤:

>

  • 创建一个这样的Dockerfile:

    From php:7.0-apache
    copy src/ /var/www/html
    EXPOSE 80
    

    从我有dockerfile的地方构建容器:

    $ docker build -t mytest .
    

    生成图像“mytest”后,我使用以下工具运行它:

    $ docker run  -p 80 mytest
    

    这就是我得到的错误:

    AH00558: apache2:无法可靠地确定服务器的完全限定域名,使用172.17.0.2。全局设置'ServerName'指令以禁止此消息AH00558: apache2:无法可靠地确定服务器的完全限定域名,使用172.17.0.2。全局设置'ServerName'指令以禁止此消息[Sun Sep17 16:25:12.340564 2017][mpm_prefork:通知][pid 1]AH00163: Apache/2.4.10(Debian)PHP/7.0.23配置--恢复正常操作[Sun Sep17 16:25:12.340666 2017][core:通知][pid 1]AH00094:命令行:'apache2-D FOREGROUND'

    所以,我不知道如何解决它。知道吗?

  • 共有3个答案

    公良俊楚
    2023-03-14

    为避免该警告,您可以在IP中设置ServerName。

    参见此示例:tagplus5/docker-php/7-apache/Dockerfile

        apt-get install -y --no-install-recommends iproute2 apache2 php7.0 libapache2-mod-php7.0 \
            php7.0-mysql php7.0-sqlite php7.0-bcmath php7.0-curl ca-certificates && \
        apt-get autoremove -y && \
        rm -rf /var/lib/apt/lists/* && \
    echo "ServerName $(ip route get 8.8.8.8 | awk '{print $NF; exit}')" >> /etc/apache2/apache2.conf && \
    

    (虽然iproute在Mac上的工作方式可能不同:这取决于您的主机。请参阅iproute2mac第8期)

    邹晟睿
    2023-03-14

    这不是一个错误,它只是一个警告,您可以放心地忽略它。意思是没有设置服务器名,因此它将假设机器IP相同。

    如果您查看/etc/apache2/sites-可用性中的默认配置,您会发现000-default.confdefault-ssl.conf

    root@d591ab6febff:/etc/apache2/sites-available# cat 000-default.conf
    <VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com
    
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
    
        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
    </VirtualHost>
    

    ServerName指令在配置文件中注释

    #ServerName www.example.com
    

    因此,如果您担心警告,您应该将其更改为您想要的值,如下所示

    ServerName www.tarunlalwani.com
    ServerAlias tarunlalwani.com
    

    您需要在文件夹中创建一个配置,然后使用Dockerfile从默认配置覆盖文件。然后警告就会消失。

    孔梓
    2023-03-14

    我想提供另一种(可能更像Docker-ish)解决警告消息的方法。但首先,在盲目设置服务器名之前,了解Apache在计算域名方面实际做了什么是有意义的。有一篇好文章在http://ratfactor.com/apache-fqdn.html这就解释了这个过程。

    一旦我们可以确认Apache用来查找名称的是getnameinfo,并且它使用了/etc/nsswitch。为了确定首先查找的位置,我们可以找出要修改的内容。

    如果我们检查一下nsswitch。conf在容器内,我们可以看到它在外部DNS之前的文件中查找主机:

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

    知道了这一点,也许我们可以在Docker运行时影响文件,而不是将其添加到我们的配置文件中?

    如果我们看一看Docker run参考文档,在https://docs.docker.com/engine/reference/run/#managing-蚀刻。它提到:

    容器将有 /etc/hosts行,这些行定义容器本身的主机名以及localhost和其他一些常见的东西。

    因此,如果我们只设置容器主机名,它将被添加到主机中,这将解决Apache警告。幸运的是,使用主机名或h选项很容易做到这一点。如果我们将其设置为完全限定的域名,Docker将在我们的/etc/hosts文件中设置它,Apache将获取它。

    尝试这个很容易。带有警告的示例(没有主机名):

    $ 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选项设置为完全限定的域名:

    $ 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和完全限定域名的学习。

     类似资料:
    • 问题内容: 我试图在CentOS 5.0上重新启动Apache服务器,并收到以下消息: httpd:无法可靠地确定服务器的标准域名,对ServerName使用127.0.0.1 这是文件: 这是文件: 我在Apache httpd.conf文件中也有此文件: 但是,重新启动Apache时,我仍然收到第一条错误消息。 问题答案: 您的主机文件不包含有效的FQDN,也不包含FQDN。FQDN必须包括主

    • 问题内容: 我正在使用urllib2从服务器下载数据。但是我需要确定所连接服务器的IP地址。 请不要要求我使用URL查找IP地址,因为这不能保证从中下载数据的服务器和IP地址查询在使用“ HTTPRedirects”或负载平衡服务器时都解析为相同的IP地址。 问题答案: 在进行任何重定向之后,返回用于实际检索资源的URL。然后,将主机名移出并移交以获得IP地址。 对于给定的主机名,某些主机可能具有

    • 本文向大家介绍Tornado服务器中绑定域名、虚拟主机的方法,包括了Tornado服务器中绑定域名、虚拟主机的方法的使用技巧和注意事项,需要的朋友参考一下 Tornado默认是监听IP加端口形式,由于Tornado在国内用的人极少,资料更是鳞毛凤角。下面说说Tornado如何绑定域名。 默认Tornado的hello word是这么来的 运行后,使用浏览器访问IP+8888端口 如果你想支持域名访

    • 瞧,它确实返回了一个比我最初预期的更大的数字,迫使我使用行中第一个单元格中的值作为循环的退出条件,如下所示: 这对我来说很有效,但我想知道是否有更好的方法。

    • 编辑: 编辑:实际上我使用的是Java7(我认为Java8正在运行),但它不是

    • 本文向大家介绍详解Tomcat服务器绑定多域名和虚拟目录的方法,包括了详解Tomcat服务器绑定多域名和虚拟目录的方法的使用技巧和注意事项,需要的朋友参考一下 tomcat采用默认安装,要想tamcat直接绑定多个域名,这里我们需要修改配置文件:C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\server.xml server