forked fromfuhrysteve/php-docker-apache-example
- Notifications
You must be signed in to change notification settings - Fork0
kekbait/php-docker-apache-example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
docker run -p 8080:80 -v $(pwd)/myapp:/var/www/html --name le_php php-docker-apache-example ./vendor/bin/phpunit tests/tests.phpdocker build -t php-docker-apache-example .
# build the docker imagedocker build -t php-docker-apache-example.# run the docker container on this machine. Expose its internal# port 80 to this machine's port 8080docker run -d -p 8080:80 php-docker-apache-example
And you can see the result here:
# to spin up additional containers on different ports, you might# do something like this:docker run -d -p 5000:80 php-docker-apache-exampledocker run -d -p 5001:80 php-docker-apache-exampledocker run -d -p 5002:80 php-docker-apache-exampledocker run -d -p 5003:80 php-docker-apache-exampledocker run -d -p 5004:80 php-docker-apache-exampledocker run -d -p 5005:80 php-docker-apache-exampledocker run -d -p 5006:80 php-docker-apache-exampledocker run -d -p 5007:80 php-docker-apache-example
Now you have 8 concurrent webservers running, all ready to servetraffic on 8 different ports. A load balancer would typicallychoose which container to send a request to based on load /availability / etc.
If you wanted to deploy a new version of your software but are nervousof breaking something, you could spin up new containers and leave theold ones running. If anything bad happens, switching back to the oldcontainers is quick and reliable.
- The PHP application code goes in
myapp/
- The first line of the Dockerfile
FROM php:7.0-apache
means "usethe official maintained image (which happens to be debian based)with php version 7 and apache installed on it". When you rebuild yourimages, you get any security updates along with it for free. - Developers are typically responsible for creating and maintainingthe Dockerfile and any dependencies their code makes use of (forexample, if they want to use ImageMagick to convert images tothumbnails, they will have to put it in the Dockerfile, otherwisetheir code would break).
- Applications should avoid writing to the filesystem (when uploadingfiles, for instance) and prefer to use object storage, such asAmazon S3 instead. The reason for this is that it is a maintenanceheadache. It is definitely possible. It is usually more annoyingthan alternatives.
- In development, the developer would likely also use a docker containerfor MySQL / similar persistent data stores. In production, their Dockercontainer would likely connect to a different (managed) database.