apachedockerdocker-compose

Apache couldn't determine servername on docker container


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

But when I try to add a custom vhost configuration and restart apache I get the warning that Apache was unable to determine the global name: 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

What's important is the fact that when I log into container's shell and manually run service apache2 restart I do not get this warning anymore.

How can I suppress that on the build? Should I provide the vhost to the composer somehow else?

Here is my docker-compose.yml is like:

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}

Then, Dockerfile that adds my own available site:

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

And obviously site config:

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

Solution

  • As indicated here and in the warning message you can set the ServerName property to localhost in /etc/apache2/apache2.conf from within the Dockerfile.