The PHP podcast where everyone chimes in.

Originally aired on

June 23rd, 2016

048: Docker & PHP

The demand for DevOps skills is growing more and more in modern web development. But all the hype and demand is met with myriad DevOps tools. Staying abreast of how these tools can help make our jobs easier can be daunting. So today we take a closer look at one of these tools called Docker which takes a microservices-architecture approach to managing your servers.

with


Docker & PHP Show Summary


What is docker?

  • A deployment strategy
  • We use it in a similar way to something like vagrant
  • It allows us to deploy our code into a pre-built environment
  • Reduces the 'works on my machine' problem

How does docker differ from tools like ansible, puppet, chef?

  • Configuration Management Tools allow us to describe a full virtual machine configuration
  • A docker file describes a container, which is 'smaller' than a virtual machine
  • A container only contains the environment necessary to run a single service
  • Tools like ansible fit into a docker workflow in configuring and managing the host environment that docker sits on

Docker files can be considered as 'snapshots'

  • A docker snapshot can freeze 100% of the dependencies for an application, but we can also choose to exclude certain parts of an environment from a snapshot (e.g: we could exclude everything in /var/www/html from the snapshot process)
  • Docker makes it easy to tag and roll back changes
  • If a bug exists in production, we don't need to try to recreate the same conditions in a development environment: If we pull down a docker image that was deployed to the production server, it is the exact same thing that was in production

A helpful metaphor

  • A docker image is like a class. A docker container is like an object.
  • Docker images extend other images
  • There are a number of official docker images (for ubuntu, PHP, ngnix, etc)
  • Docker images that we create will extend one of these base images
  • We create multiple layers of these
  • A container is an instance of an image: Having defined suitable images (classes) we can then instantiate many containers (objects)

Best Practices

  • We should strive for 1 process per container as far as possible
  • This makes it easier to swap out components
  • Think of it like programming: this is like an object having a single responsibility
  • Docker Compose allows us to define an application with many docker containers, including how docker containers inside that environment communicate with each other

Components of Docker:

How does Copy on Write FileSystem work?

  • As you build a docker file, every command creates a new 'layer'
  • Layers can be shared between containers
  • If your docker containers share common layers, they don't have to be duplicated.
  • For example, if you already have an ubuntu container and you add a ngnx container (which shares common ancestry with the ubuntu container), the ngnx container only needs to download the difference between the 2 (i.e: the 'layers' where ngnx was installed on top of ubuntu).
  • This makes it quick to deploy applications with docker because deploying a new version only requires us to download and apply the changed/different layers each time.

How do we manage many docker containers?

What are the disadvantages associated with using docker?

  • Initially docker moved quickly but sometimes broke backwards compatibility
  • More recently, docker has become much more stable
  • Support for MacOS and Windows still has some problems and lags behind linux support

Other resources

Phillip Shipley


Chris Tankersley


Developer Shout-Out

The Developer Shout-Out recognizes developers in the community for their contributions.

For this episode the panel guests, Phillip and Chris nominated Eli White for the Developer Shout-Out segment.

Thank you, Eli White for all your hard work with the PHP community. A $50 Amazon gift card is on its way to you.

$50 Amazon gift card sponsored by Laracasts

Laracasts

It's like Netflix for developers.

Show Notes Credit

Chris Shaw

Thank you Chris Shaw for authoring the show notes for this episode!

If you'd like to contribute show notes and totally get credit for it, check out the show-notes repo!