just for thinking about this… how would you do the setup with a real server, webserver and php.
NOTHING is different using docker, except the commands used to do the setup
create a server (start with ubuntu)
add the apache server
add the php server plugin
do the website config (change apache.conf etc)
set the website path
set the listening ports for the https server (port=80 or 8080 or somesuch)
start the apache server
that would be your dockerfile
here is a Dockerfile for one of my php based web apps
this runs on Amazon aws, and uses an EFS shared volume as the web site source path, so the php code is not IN the container.
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
run apt-get -y upgrade
run apt-get update
run apt-get purge php*
RUN apt-get -y install \
apache2 php7.0-mysql php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0 php7.0-xml php7.0-curl php7.0-zip curl php-gd php7.0-mbstring libapache2-mod-php nfs-common iputils-ping dnsutils
# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
run a2dismod mpm_event
run a2enmod mpm_prefork
# Manually set up the apache environment variables
ENV APACHE_RUN_USER root
ENV APACHE_RUN_GROUP root
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV WEBROOT_PATH /store-code
# Expose apache.
# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
ADD apache.conf /etc/apache2/apache2.conf
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUND
then to make this work (on a local docker host machine)
docker run -d -v source_path:/var/www/html -p0:80 container_tag
the -p0:80 means map the container port 80 to the next available free port on host.
docker inspect will show that mapping…
then http://host_ip:host_port/??? will run the php app just like always
here is my aws ECS cluster design
the web server box is the ECS instance (ec2), and it is a docker host. (cpu and memory), aws auto scaling group
the docker image IS the web server code(apache). (app code and data access) aws cluster service, task definition
so this has dual scalability
- ecs instance(ec2) size
- task (docker container) size
the aws ELB does all the wiring of the external port to the exposed docker instance port
there is only one port (80) into the VPC, and it is to the load balancer
the PHP code is on the EFS code volume, mapped to the volume $WEBROOT_PATH in the container
EFS volumes are terribly slow, so a CDN is used to cache the content outside the ECS cluster to improve speed.