Apache not running automatically on docker compose up Apache not running automatically on docker compose up apache apache

Apache not running automatically on docker compose up


Judging from the output of your logs the image which is running when you do docker-compose up is not using the CMD you have specified. This is probably because it was built the first time you ran docker-compose up and was not subsequently rebuilt. To get around this try running with docker-compose up --build.

When I built & ran your image (with the docker-compose.yml you provided) I did get apache starting - my output was like:

Successfully built d65dabcc2595Creating apachenotrunningautomaticallyondockercomposeup38280007_frontend_1Attaching to apachenotrunningautomaticallyondockercomposeup38280007_frontend_1frontend_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.25.0.2. Set the 'ServerName' directive globally to suppress this message

I think that starting apache in this way is not best practice given the image you are using though - the recommended way would be with a service file as phusion/baseimage uses a custom init system to get around some potential issues with Docker.

You can follow their recommended way by creating a service file for apache. If you create (in your frontend folder) a script called apache.sh (make sure it is chmod +x) with these contents:

#! /bin/shexec /usr/sbin/apache2ctl -D FOREGROUND

And change your Dockerfile to look like this:

FROM phusion/baseimage:0.9.16MAINTAINER Raheel <raheelwp@gmail.com># ApacheRUN apt-get updateRUN apt-get -y install apache2# PHPRUN apt-get -y install python-software-propertiesRUN add-apt-repository ppa:ondrej/phpRUN apt-get updateRUN apt-get -y --force-yes install php7.0RUN apt-get -y --force-yes install libapache2-mod-php7.0 php7.0-curl php7.0-jsonRUN mkdir /etc/service/apacheADD apache.sh /etc/service/apache/runRUN chmod +x /etc/service/apache/run

Then it will use the init system provided.

In answer to your second question I think you have 2 main options:

  1. If you must keep them in a VOLUME & be accessible to both your user on the host (which is presumably the one with uid & gid 1000) then you could ensure that the user which apache runs your app as has the same uid & gid as your user on the host (create another user & tell apache to use that user in your apache config). This will work but will be far less portable to systems where the user on the host is different.

  2. Add this to your Dockerfile and drop the volume options from docker-compose.yml:

    RUN mkdir -p /var/www/html/frontend/COPY . /var/www/html/frontend/RUN chown -R www-data:www-data /var/www/html/frontend

If it were me I would choose option 1 for a development environment (as portability is likely less of an issue) but option 2 for any kind of production deployment (as a large benefit of docker is the immutability of containers).