Skip to content

Instantly share code, notes, and snippets.

@taion809
Created July 12, 2014 02:47
Show Gist options
  • Save taion809/60c24484beeb4bb0feec to your computer and use it in GitHub Desktop.
Save taion809/60c24484beeb4bb0feec to your computer and use it in GitHub Desktop.

Dockerizing your PHP application

Why?

Why would you want to utilize Docker to package and deliver your application? The most compelling reason, in my mind, is the idea of immutable infrastructure. The ability to run the same exact software on the same infrastructure each time you deploy regarless of when you deploy. I once posted an article describing how I used Docker to contain and deliver a legacy nodejs application. That same application still runs and can be easily deployed to another server and run exactly the same as it did the very first day.

Sounds great, so what do you do?

The first thing is get familiar with the documentation. This article will not discuss the basics of using Docker.

Awesome, let's go.

In order to dockerize our application we will be using a pattern called "data containers" to actually contain our application code and be linked with our web server and our php instance.

Sounds easy right? Let's look at some code.

[data container code]

The purpose for this is really in the name, its only reason to exist in this world is to be linked with other containers.

Let's move on to the web server.

[nginx container code]

For the webserver I have selected nginx, it serves my purpose quite well and easily fits this workflow by allowing us to pass the interpreting of php code to another container and from our webserver deliver static assets.

So let's link this with our data container and test it out.

[docker linking code] [curl test]

Wonderful.

Moving on to php,

[php container code]

This container is using php-fpm to interpret our application code. It is pretty straight forward, listen on tcp port 9001, interpret code, maybe ponder meaning of life.

So that seems like a big pain in the butt, unfortunately I can't make that any easier.

Oh wait... yes I can! Checkout fig and then come back here for the container redux.

Back? OK.

@onel0p3z
Copy link

hey there, did you ever published this or made it to have [* container code ]??? Currently looking at a similar scenario and love to read your work and conclusions if possible. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment