Apache无法确定docker容器上的servername

我正在尝试为现有站点设置定制的泊坞窗容器。 要做到这一点,我想提供一个ServerName我自己的自定义vhostconfiguration。

但是,当我尝试添加自定义vhost configuration并重新启动Apache时,我得到了Apache无法确定全局名称的警告: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message

重要的是,当我login到容器的shell并手动运行service apache2 restart我不会再收到这个警告。

我怎样才能抑制构build? 我应该以其他方式将作曲者提供给composer php吗?

这是我docker-compose.yml是这样的:

 version: '3' services: web: build: context: ./etc/php args: - APP_HOST=${APP_HOST} ports: - ${APP_PORT}:80 - ${APP_PORT_SSL}:443 volumes: - ./var/bin/:/tmp/bin/ - ./app/:/var/www/html/ - ./log/:/var/log/ - ./etc/php/conf/:/usr/local/etc/php/conf.d/ environment: - VIRTUAL_HOST=${VIRTUAL_HOST} 

然后,添加我自己的可用站点的Dockerfile

 FROM php:7.0-apache ENV TERM=xterm LABEL maintainer="Derek P Sifford <dereksifford@gmail.com>" \ version="0.15.2-php7.0" ARG APP_HOST ENV APP_HOST=$APP_HOST ADD ./sites/app.conf /etc/apache2/sites-available/app.conf RUN sed -i 's/ServerName APP_HOST/ServerName '$APP_HOST'/g' /etc/apache2/sites-available/app.conf RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \ && a2enmod rewrite expires \ && a2dissite 000-default.conf \ && a2ensite app.conf \ && service apache2 restart WORKDIR /app EXPOSE 80 443 

显然网站configuration:

 <VirtualHost *:80> DocumentRoot "/var/www/html" ServerName APP_HOST SetEnv APPLICATION_ENV "development" <Directory "/var/www/html"> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

如此处所示,在警告消息中,您可以从Dockerfile内的/etc/apache2/apache2.conf中将ServerName属性设置为localhost

我认为您的configuration存在问题,因为您将其复制并安装到卷上。 我认为你的configuration不应该在你的容器是活着的时候发展,所以你不需要挂载它。

所以,试着从docker-compose.yml中删除这一行:

 - ./etc/php/conf/:/usr/local/etc/php/conf.d/ 

在你的apache容器实例上,你应该把IP 172.26.0.2放在/etc/hosts并提供一个完全限定的名字给它

172.26.0.2 vbox.test.com

然后用vbox.test.comreplace主机名

要么

localhost放在serverName中。

这应该对你有所帮助