Apache couldn't determine servername on docker container

时间:2017-12-18 08:32:07

标签: apache docker docker-compose

I am trying to set up a customized docker container for an existing site. To do so I want to provide my own custom final ? value = ... configuration with a vhost.

But when I try to add a custom ServerName and restart apache I get the warning that Apache was unable to determine the global name: vhost configuration

What's important is the fact that when I log into container's shell and manually run 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 I do not get this warning anymore.

How can I suppress that on the build? Should I provide the service apache2 restart to the composer somehow else?

Here is my vhost is like:

docker-compose.yml

Then, 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} that adds my own available site:

Dockerfile

And obviously site config:

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

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我认为您的配置存在问题,因为您将其复制并将其安装在卷上。我认为当您的容器处于活动状态时,您的配置不应该发展,所以您不需要安装它。

因此,尝试从docker-compose.yml中删除此行:

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

答案 2 :(得分:0)

在您的apache容器实例上,您应将IP 172.26.0.2放入/etc/hosts并为其提供完全限定的名称,例如

  

172.26.0.2 vbox.test.com

然后将主机名替换为vbox.test.com

localhost放入serverName。

This可以帮到你。

相关问题