Base docker image to run PHP applications on Apache
To run apache in a background process, simply start the container using the following command:
docker run -d -p 80:80 --name my-running-app mobilesnapp/apache-php7
-p 80:80 publishes port 80 in the container to 80 on the host machine. -d detaches from the process, use docker ps and docker stop to … stop.
Sometimes you’ll want to debug issues with the container; maybe there are PHP configuration issues or you want to view error logs. To do that you can start the container in interactive mode and then start apache manually:
docker run -i -t -p 80:80 my-running-app /bin/bash
apachectl start
As per the defaults, Apache will use the bundled "snakeoil" key when serving SSL. Obviously this isn't sufficient or advisable for production, so you'll want to mount your real keys onto /etc/ssl/. If you name them "certs/ssl-cert-snakeoil.pem" and "private/ssl-cert-snakeoil.key", you'll be able to get by with the default config. Otherwise, you'll want to include a revised site definition. If you don't want to use SSL, you can avoid forwarding port 443 when launching the container (see below).
If you’re actively developing you want to be able to change files in your usual editor and have them reflected within the container without having to rebuild it. The -v flag allows us to mount a directory from the host into the container:
docker run -p 80:80 -d -v /Users/myapp/site:/var/www/html --name my-running-app mobilesnapp/apache-php7
and browse to the host's IP address using http.
Serving actual content with SSL support:
docker run -p 80:80 -p 443:443 -d -v /Users/myapp/site:/var/www/html --name my-running-app mobilesnapp/apache-php7
Using non-standard ports:
docker run -p 8080:80 -p 8443:443 -d -v /Users/myapp/site:/var/www/html --name my-running-app mobilesnapp/apache-php7
If you’re actively developing you want to be able to change files in your usual editor and have them reflected within the container without having to rebuild it. The -v flag allows us to mount a directory from the host into the container:
docker run -p 80:80 -d -v /Users/myapp/site:/var/www/html --name my-running-app mobilesnapp/apache-php7
MobileSnapp (support@mobilesnapp.com)