Apache couldn't determine servername on docker container

大兔子大兔子 提交于 2021-02-18 08:37:06

问题


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>

回答1:


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.




回答2:


I think there is a problem with your configuration, because you copy it and mount it on a volume. I think your configuration should not evolve when your container is live, so you don't need to mount it.

So, try to remove this line from your docker-compose.yml :

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



回答3:


On your apache container instance, you should put IP 172.26.0.2 in /etc/hosts and provide a fully qualified name to it e.g.

172.26.0.2 vbox.test.com

Then replace hostname with vbox.test.com

or

put localhost in serverName.

This should help you.



来源:https://stackoverflow.com/questions/47864581/apache-couldnt-determine-servername-on-docker-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!