MAINTAINER Raheel <email@example.com>
RUN apt-get update
RUN apt-get -y install apache2
RUN apt-get -y install python-software-properties
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
RUN apt-get -y install php7.0
RUN apt-get -y install libapache2-mod-php7.0 php7.0-curl php7.0-json
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
service apache2 start
*** Running /etc/my_init.d/00_regen_ssh_host_keys.sh...
*** Running /etc/rc.local...
*** Booting runit daemon...
*** Runit started as PID 9
Jul 10 08:27:33 6d5c09e83a98 syslog-ng: syslog-ng starting up; version='3.5.3'
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 d65dabcc2595 Creating apachenotrunningautomaticallyondockercomposeup38280007_frontend_1 Attaching to apachenotrunningautomaticallyondockercomposeup38280007_frontend_1 frontend_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/sh exec /usr/sbin/apache2ctl -D FOREGROUND
And change your Dockerfile to look like this:
FROM phusion/baseimage:0.9.16 MAINTAINER Raheel <firstname.lastname@example.org> # Apache RUN apt-get update RUN apt-get -y install apache2 # PHP RUN apt-get -y install python-software-properties RUN add-apt-repository ppa:ondrej/php RUN apt-get update RUN apt-get -y --force-yes install php7.0 RUN apt-get -y --force-yes install libapache2-mod-php7.0 php7.0-curl php7.0-json RUN mkdir /etc/service/apache ADD apache.sh /etc/service/apache/run RUN 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:
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.
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).