• Stars
    star
    362
  • Rank 117,671 (Top 3 %)
  • Language
    Dockerfile
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

*WORK IN PROGRESS* sample PHP/Laravel app for Docker examples

PHP (Laravel) + Docker Hello World, for Showing Good Defaults for Using A PHP Stack in Docker

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.

Official Laravel Docker Environment

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.

Contribuitions

This project was made possible in part with support and development from PrinterLogic.

Local Development Features

  • Dev as close to prod as you can. docker-compose builds a local development image that is just like production image except for the below dev-only features needed in image. Goal is to have dev env be as close to test and prod as possible while still giving all the nice tools to make you a happy dev.
  • Prevent needing node/npm on host. Installs 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.
  • One line startup. Uses docker-compose up for single-line build and run of local development server.
  • Edit locally while code runs in container. docker-compose uses proper bind-mounts of host source code into container so you can edit locally while running code in Linux container.
  • Enable debug from host to container. opens the legacy debug port 5858 and new inspect port 9229 for using host-based debugging like chrome tools or VS Code. Nodemon enables --inspect by default in docker-compose, but you can change to --debug for < 6.3 debugging.
  • Quick re-builds. 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.

Production-minded Features

  • Use Docker build-in healthchecks. uses Dockerfile HEALTHCHECK with php-fpm /ping route to help Docker know if your container is running properly.
  • Nginx + PHP-FPM in one container. Supervisor is used to combine the two services, Nginx and PHP-FPM in a single container. Those two services have to work together to give you a webserver and PHP processor. Unlike Apache + mod_php, which runs under the Apache process and only needs to start one process on container startup, the combo of Nginx + PHP-FPM have to be started separately. Docker is designed to run a single process with CMD in the Dockerfile, so the simple Supervisor program is used to manage them with a simple config file. Having them both in one container makes the app easier to manage in my real-world experience. Docker has a Docs page on various ways to start multi-service containers, showing a Supervisor example. So far, the Nginx + PHP-FPM combo is the only scenario that I recommend using multi-service containers for. It's a rather unique problem that doesn't always fit well in the model of "one container, one service". You could use two separate containers, one with 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.

Assumptions

  • You have Docker and Docker-Compose installed (Docker for Mac, Docker for Windows, get.docker.com and manual Compose installed for Linux).
  • You want to use Docker for local development (i.e. never need to install php or npm on host) and have dev and prod Docker images be as close as possible.
  • You don't want to lose fidelity in your dev workflow. You want a easy environment setup, using local editors, debug/inspect, local code repo, while web server runs in a container.
  • You use docker-compose for local development only (docker-compose was never intended to be a production deployment tool anyway).
  • The docker-compose.yml is not meant for docker stack deploy in Docker Swarm, it's meant for happy local development.

Getting Started

If this was your app, to start local development you would:

  • Running docker-compose up is all you need. It will:
  • Build custom local image enabled for development.
  • Start container from that image with ports 80, 443, 9000, and 9001 open (on localhost or docker-machine).
  • Mount the pwd to the app dir in container.
  • If you need other services like databases, just add to compose file and they'll be added to the custom Docker network for this app on up.
  • If you need to add packages to Composer, npm, bower, etc. then stop docker-compose and run docker-compose up --build to ensure image is updated.
  • Be sure to use 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.

More Repositories

1

udemy-docker-mastery

Docker Mastery Udemy course to build, compose, deploy, and manage containers from local development to high-availability in the cloud
JavaScript
5,263
star
2

node-docker-good-defaults

sample node app for Docker examples
JavaScript
2,323
star
3

dogvscat

Sample Docker Swarm cluster stack of tools
HCL
504
star
4

nodejs-rocks-in-docker

DockerCon "Docker for Node.js" examples
Dockerfile
494
star
5

docker-mastery-for-nodejs

Docker Mastery for Node.js Projects, From a Docker Captain
JavaScript
412
star
6

awesome-swarm

All the awesome tools, docs, and training on Docker and Mirantis Swarm Mode (SwarmKit)
385
star
7

docker-vackup

Script to easily backup and restore docker volumes
Shell
362
star
8

jekyll-serve

Jekyll in a Docker Container For Easy SSG Development
Dockerfile
336
star
9

docker-ci-automation

GitHub Actions automation examples with Docker's official actions
Shell
247
star
10

kubernetes-mastery

Kubernetes course on Udemy from @BretFisher and @jpetazzo
Shell
233
star
11

multi-platform-docker-build

Using BuildKit and TARGETPLATFORM for cross-platform Dockerfiles
Dockerfile
125
star
12

compose-dev-tls

Easy Traefik TLS proxy plus certificate generation for Docker Compose local development use
Shell
111
star
13

github-actions-templates

Reusable GitHub Actions workflow examples for cloud native DevOps
Dockerfile
75
star
14

podspec

Kubernetes Pod Specification Good Defaults
71
star
15

browncoat

Container for testing app failures in orchestrators. It aims to misbehave.
JavaScript
69
star
16

httping-docker

Ping with HTTP requests, built directly from master
C
52
star
17

docker-build-workflow

A Reusable Workflow of the Docker GitHub Actions
Dockerfile
42
star
18

super-linter-workflow

A Reusable Workflow of the Super-Linter GitHub Action
37
star
19

gha-runners

Terraform to create GitHub Action self-hosted runners in EC2 using ASG
HCL
29
star
20

slack-signup

Slack Team Access Request Form in Meteor
JavaScript
27
star
21

container-security-steps

Docker and Kubernetes security steps to help you create, build, test, and run safer in containers
26
star
22

stress

Docker images for stressing cpu and memory
Dockerfile
25
star
23

sysbench-docker-hpe

Sysbench Dockerfiles and Scripts for VM and Container benchmarking MySQL
Shell
19
star
24

BretFisher

18
star
25

petclinic

sample dockerization of a Java Spring Boot app
Java
17
star
26

redis-tini

Docker image of official redis with tini added for liveness healthchecks that reap zombies
Dockerfile
17
star
27

nodemongoapp

Docker Example Node + Mongo App
JavaScript
11
star
28

initcontainers

Kubernetes initContainers examples and good defaults
10
star
29

bret.run

Static files for easy gettin' stuff
Shell
7
star
30

PowerShell-Profile

Microsoft.PowerShell_profile.ps1
PowerShell
7
star
31

resume

My Resume, hopefully current.
HTML
5
star
32

gitops-argocd

4
star
33

completion-image

Generates completion certificates (images) for students based on a template image and a CSV file containing student names.
Go
3
star
34

wordsmith-k8s

Manifests for Docker's wordsmith demo
3
star
35

cheese

Simple web servers of cheese for yummy demos.
HTML
3
star
36

docker-github-actions-monorepo-example

3
star
37

slide-to-image

JavaScript
1
star
38

.github

1
star
39

dotfiles

My public dotfiles for Codespaces and examples
Shell
1
star
40

gatsby-starter-netlify-cms

JavaScript
1
star
41

nodeBeginnerBookLearnings

Me just learning the node code from the Excellent
1
star
42

AutoSPInstaller-User-Creator

I use this PowerShell Script with www.autospinstaller.com to automate (most) of a SharePoint 2010 deployment
PowerShell
1
star
43

katacoda-scenarios

https://www.katacoda.com/bretfisher
1
star
44

pmx-docker

Shell
1
star