Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Containerising Applications For Docker

Containerising Applications For Docker

Containers in general - and Docker in particular - are hot tech. Not only are they a great replacement for many roles where we'd normally use a virtual machine, but they're also a great way to distribute applications along the pipeline from dev to test to production. And they're great for running PHP web-based apps!

In this talk, Stuart will show you how he designs Docker images that can be used to run PHP-based web applications in dev, test and in production. He'll walk through why dev Docker images are different to test/production images, and how to easily convert a dev Docker image into a test/production image without undermining the whole point of using Docker in the first place.

Presented @PHPEssex in Chelmsford, Essex, UK on 21st February 2018.

Stuart Herbert

February 21, 2018
Tweet

More Decks by Stuart Herbert

Other Decks in Programming

Transcript

  1. Industry veteran: architect, engineer, leader, manager, mentor F/OSS contributor since

    1994 Talking and writing about PHP since 2004 Chief Software Archaeologist @GanbaroDigital About Stuart
  2. @GanbaroDigital This is a follow-up to my talk Docker for

    PHP Dev Environments presented @PHPMinds in 2017
  3. @GanbaroDigital I’ve been working with clients who want to Dockerize

    everything. The same points come up every time.
  4. @GanbaroDigital In This Talk ... 1. Common Understanding 2. Image

    and Container Properties 3. Putting It All Together 4. Common Questions
  5. @GanbaroDigital You can use the same image in dev, test,

    & production to guarantee the same behaviour everywhere.
  6. @GanbaroDigital You can use the same image in dev, test,

    & production to guarantee the same behaviour everywhere.
  7. @GanbaroDigital You can use the same image in dev, test,

    & production to guarantee the same software everywhere.
  8. @GanbaroDigital Differences Wanted ... • Logging levels • PHP profiler

    modules • PHP opcache config • Baking your app into the image
  9. @GanbaroDigital Differences Wanted ... • Logging levels • PHP profiler

    modules • PHP opcache config • Baking your app into the image
  10. @GanbaroDigital Differences Wanted ... • Logging levels • PHP profiler

    modules • PHP opcache config • Baking your app into the image
  11. @GanbaroDigital Differences Wanted ... • Logging levels • PHP profiler

    modules • PHP opcache config • Baking your app into the image
  12. @GanbaroDigital Persistent Data Includes ... • Databases • File uploads

    • Session data • Auto-upgrades / plugin installs (Wordpress) • Logs
  13. @GanbaroDigital Persistent Data Includes ... • Databases • File uploads

    • Session data • Auto-upgrades / plugin installs (Wordpress) • Logs
  14. @GanbaroDigital Persistent Data Includes ... • Databases • File uploads

    • Session data • Auto-upgrades / plugin installs (Wordpress) • Logs
  15. @GanbaroDigital Persistent Data Includes ... • Databases • File uploads

    • Session data • Auto-upgrades / plugin installs (Wordpress) • Logs
  16. @GanbaroDigital Persistent Data Includes ... • Databases • File uploads

    • Session data • Auto-upgrades / plugin installs (Wordpress) • Logs
  17. @GanbaroDigital 5 Key Design Questions • How can I break

    my image up into layers? • What does my app need? • How do I configure everything? • Where will persistent data go? • How do I avoid all other writes to the FS?
  18. @GanbaroDigital • Your (minimal) operating system of choice • +

    anything all your child images regularly need • + convenience tools for when (not if) you shell into the containers • + standardise volume mount points
  19. @GanbaroDigital “Get it right in the base layer. Don’t have

    to put it right further up in your image stack.
  20. @GanbaroDigital Why A Web Server Image? • Standalone use: static

    sites • Shared basis: PHP, Python, Ruby, etc etc
  21. @GanbaroDigital Apache + mod_php • mod_php runs inside the Apache

    process • You can’t split a single process across two containers
  22. @GanbaroDigital • This layer is optional • Build a vanilla

    image for your base app (e.g. Wordpress, Magento) • Add in any common plugins/modules • Use as the base for multiple customisations down the road
  23. @GanbaroDigital Base Web Server PHP Wordpress Your App Ubuntu Server

    Nginx or Apache PHP-FPM or mod_php Base application Profit :)
  24. @GanbaroDigital Base Web Server PHP Wordpress Your App Ubuntu Server

    Nginx or Apache PHP-FPM or mod_php Base application Profit :)
  25. @GanbaroDigital ?? ?? Can you run a database server (e.g.

    MySQL, MongoDB) inside a container?
  26. @GanbaroDigital Databases do not need to be co-located with your

    app. So run them in their own container.
  27. @GanbaroDigital • Most of my containers are behind a proxy

    or load balancer of some kind. • Can’t reach them from an off-host network. • One less thing to worry about.
  28. @GanbaroDigital A lot of the advice out there is built

    around port forwarding. I prefer to run my containers with their own IP addresses.
  29. @GanbaroDigital 5 Key Design Questions • How can I break

    my image up into layers? • What does my app need? • How do I configure everything? • Where will persistent data go? • How do I avoid all other writes to the FS?
  30. @GanbaroDigital Base Web Server PHP Wordpress Your App Ubuntu Server

    Nginx or Apache PHP-FPM or mod_php Base application Profit :)
  31. @GanbaroDigital “Get it right in the base layer. Don’t have

    to put it right further up in your image stack.