我刚刚开始使用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: 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'
所以,我不知道如何解决它.有帮助吗?
And*_*inn 22
我想提供另一种(可能更多的Docker-ish)解决警告信息的方法.但首先,在盲目设置之前理解Apache实际在做什么来理解域名是有意义的ServerName.http://ratfactor.com/apache-fqdn.html上有一篇很好的文章解释了这个过程.
一旦我们确认这getnameinfo是Apache用来查找名称以及它用于/etc/nsswitch.conf确定首先进行查找的位置,我们就可以确定要修改的内容.
如果我们检查nsswitch.conf容器内部,我们可以看到它/etc/hosts在外部DNS之前查找文件中的主机:
# cat /etc/nsswitch.conf | grep hosts
hosts:          files dns
知道这一点,也许我们可以在Docker运行时影响文件,而不是将其添加到我们的配置文件中?
如果我们看看Docker运行参考文档,请参阅https://docs.docker.com/engine/reference/run/#managing-etchosts上的/etc/hosts文件部分.它提到:
您的容器将在/ etc/hosts中包含行,这些行定义容器本身的主机名以及localhost和其他一些常见内容.
因此,如果我们只设置容器主机名,它将被添加到/etc/hosts哪个将解决Apache警告.幸运的是,使用--hostname或-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和完全合格域名的知识.
jer*_*naa 10
如果您使用的是 docker,请执行以下操作:将 ServerName localhost 从 Dockerfile 添加到 apache2.conf,然后重新启动服务器
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN service apache2 restart
这应该消除警告。
您也可以从终端执行此操作
echo "ServerName localhost" >> /usr/local/etc/apache2/apache2.conf
并且不要忘记重新启动服务器
sudo systemctl restart apache2
服务器重新启动后该错误应该消失。
这不是错误,而只是警告,您可以放心地忽略它。它的意思是ServerName未设置,因此它将假定计算机IP相同。
如果您查看其中存在的默认配置/etc/apache2/sites-available,则会发现000-default.conf和default-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从默认配置覆盖文件。然后警告将消失。
| 归档时间: | 
 | 
| 查看次数: | 36386 次 | 
| 最近记录: |