This tries to be a "good defaults" example of using PHP, Nginx, PHP-FPM, Laravel, and Composer in Docker for local development and shipping to production with all the bells, whistles, and best practices. Issues/PR welcome.
NOTE: This is not a full PHP sample project. It's a collection of the Docker and Nginx related things you'll need to have this sort of setup fully in Docker. I'm not a PHP/Laravel developer, but rather an ops guy working with many smart PHP dev's. I continue to refine this repo as I work with teams to dev with, test on, and deploy production containers on PHP.
Also Note I have courses on Docker, Swarm, and upcoming Docker for Node.js here.
As of version 8 of Laravel there is an offically supported Docker development environment called 'Sail'. If you are specifically doing Laravel development you may want to check it out at the Laravel website.
This project was made possible in part with support and development from PrinterLogic.
node_modules
outside app root in container so local development won't run into a problem of bind-mounting over it with local source code. This means it will run npm install
once on container build and you don't need to run npm on host or on each docker run. It will re-run on build if you change package.json
.docker-compose up
for single-line build and run of local development server.--inspect
by default in docker-compose, but you can change to --debug
for < 6.3 debugging.COPY
in package.json
and run npm install && npm cache clean
before COPY
in your source code. This saves big on build time and keep container lean. Same for Composer and Bower.HEALTHCHECK
with php-fpm /ping
route to help Docker know if your container is running properly.nginx
and one with php:fpm
but I've tried that in production, and there are lots of downsides. A copy of the PHP code has to be in each container, they have to communicate over TCP which is much slower than Linux sockets used in a single container, and since you usually have a 1-to-1 relationship between them, the argument of individual service control is rather moot.docker-compose
for local development only (docker-compose was never intended to be a production deployment tool anyway).docker-compose.yml
is not meant for docker stack deploy
in Docker Swarm, it's meant for happy local development.If this was your app, to start local development you would:
docker-compose up
is all you need. It will:up
.docker-compose up --build
to ensure image is updated.docker-compose down
to cleanup after your done dev'ing.MIT License,
Copyright (c) Bret Fisher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.