SlideShare a Scribd company logo
Docker for PHP
Developers
Chris Tankersley
@dragonmantank
ZendCon 2016, October 2016
ZendCon, October 2016 1
What Is Docker?
ā€œDocker is an open platform for developers and sysadmins to build,
ship, and run distributed applications. Consisting of Docker Engine, a
portable, lightweight runtime and packaging tool, and Docker Hub, a
cloud service for sharing applications and automating workflows,
Docker enables apps to be quickly assembled from components and
eliminates the friction between development, QA, and production
environments.ā€
ZendCon, October 2016 2
https://www.docker.com/whatisdocker/
Containers
ZendCon, October 2016 3
Normal Bare-Metal Server
ZendCon, October 2016 4
CPU RAM HD Network
Operating System
nginx PHP DB
Virtual Machines
ZendCon, October 2016 5
CPU RAM HD Network
Operating System
nginx PHP DB
Operating System
nginx PHP DB
Operating System
Hypervisor
Containers
ZendCon, October 2016 6
CPU RAM HD Network
Operating System
nginxnginx PHP DB PHP DB
Containers Are Not New
• LXC (Linux Containers)
• OpenVZ
• Systemd-nspawn
• Qemu/kvm
• BSD Jails
• Solaris Zones
• chroot
ZendCon, October 2016 7
Docker is an Ecosystem
ZendCon, October 2016 8
Docker Engine
Docker is an Ecosystem
ZendCon, October 2016 9
Docker ComposeDocker Machine Docker Swarm
How does it work?
ZendCon, October 2016 10
Uses a variety of existing
Container technologies
Server Containers
Hyper-V Containers xhyve Virtualization
Sorry OSX < 10.10 and Windows < 10 Users
Docker Toolbox
ZendCon, October 2016 11
Let’s use Docker
ZendCon, October 2016 12
Running a container
• `docker run` will run a container
• This will not restart an existing container, just create a new one
• docker run [options] IMAGE [command] [arguments]
• [options ]modify the docker process for this container
• IMAGE is the image to use
• [command] is the command to run inside the container
• [arguments] are arguments for the command
ZendCon, October 2016 13
Running a simple shell
ZendCon, October 2016 14
Running a simple shell
ZendCon, October 2016 15
Running a simple shell
ZendCon, October 2016 16
What’s Going On?
ZendCon, October 2016 17
Ubuntu Kernel
/
+ bin/
+ etc/
+ dev/
+ home/
+ usr/
+ var/
+ lib/
+ …
nginx
bash
/
+ bin/
+ etc/
+ dev/
+ home/
+ usr/
+ var/
+ lib/
+ …
php
Running Two Webservers
ZendCon, October 2016 18
Running Two Webservers
ZendCon, October 2016 19
Running Two Webservers
ZendCon, October 2016 20
Running Two Webservers
ZendCon, October 2016 21
Running Two Webservers
ZendCon, October 2016 22
Running Two Webservers
ZendCon, October 2016 23
Running Two Webservers
ZendCon, October 2016 24
Running Two Webservers
ZendCon, October 2016 25
Some Notes
• All three containers are 100% self contained
• Docker containers share common ancestors, but keep their own files
• `docker run` parameters:
• --rm – Destroy a container once it exits
• -d – Run in the background (daemon mode)
• -i – Run in interactive mode
• --name – Give the container a name
• -p [local port]:[container port] – Forward the local port to the container port
ZendCon, October 2016 26
Volumes
ZendCon, October 2016 27
Modifying a running container
• `docker exec` can run a command inside of an existing container
• Use Volumes to share data
ZendCon, October 2016 28
Persistent Data with Volumes
• You can designate a volume with –v
• Create a named volume with `volume create`
• Volumes can be shared amongst containers
• Volumes can mount data from the host system
ZendCon, October 2016 29
Mounting from the host machine
ZendCon, October 2016 30
Mounting from the host machine
ZendCon, October 2016 31
Mounting from the host machine
ZendCon, October 2016 32
Mounting from the host machine
ZendCon, October 2016 33
Mounting from the host machine
ZendCon, October 2016 34
Mounting from the host isn’t perfect
• The container now has a window into your host machine
• Permissions can get screwy if you are modifying in the container
• Most things it creates will be root by default, and you probably aren’t root on
the host machine
• Host-mounted volumes are not portable at all
• OSX and Hyper-V VMs have limited pathings to mount
• OSX has poor I/O performance
ZendCon, October 2016 35
Named Data Volumes
• Creates a space that becomes persistent
• Can be mounted anywhere inside your images
• Have our app containers use the data volume to store data
• Use ā€˜editor containers’ to go in and modify data when needed
ZendCon, October 2016 36
Mounting Data Volumes
ZendCon, October 2016 37
Mounting Data Volumes
ZendCon, October 2016 38
Mounting Data Volumes
ZendCon, October 2016 39
Mounting Data Volumes
ZendCon, October 2016 40
Mounting Data Volumes
ZendCon, October 2016 41
Mounting Data Volumes
ZendCon, October 2016 42
Why go through the hassle?
• Data volumes are portable, depending on the driver
• Data volumes are safer
• Separates the app containers from data
• Production can use a data volume, dev can use a host volume
• Our app containers stay small
• Works directly with other tools
ZendCon, October 2016 43
Network Linking
ZendCon, October 2016 44
Docker Links
• Allows containers to ā€˜see’ each other over the network
• Each container thinks the other one is just another machine
• Containers all have an internal network address, so we don’t need to
expose everything through the host
• Legacy Links work with `--link`
• Can set up virtual networks
ZendCon, October 2016 45
More Traditional Setup
ZendCon, October 2016 46
INTARWEBS Nginx PHP-FPM
Data Volume
Port 9000
Editor
Mounting Data Volumes
ZendCon, October 2016 47
Mounting Data Volumes
ZendCon, October 2016 48
Mounting Data Volumes
ZendCon, October 2016 49
Mounting Data Volumes
ZendCon, October 2016 50
Mounting Data Volumes
ZendCon, October 2016 51
Mounting Data Volumes
ZendCon, October 2016 52
Let’s Build It
ZendCon, October 2016 53
Let’s Build It
ZendCon, October 2016 54
Let’s Build It
ZendCon, October 2016 55
Let’s Build It
ZendCon, October 2016 56
Let’s Build It
ZendCon, October 2016 57
More Notes!
• We can now rebuild sections of the app as needed
• We can restart nginx without impacting PHP
• We can extend much easier
• Docker 1.12 has added a whole bunch of new stuff
ZendCon, October 2016 58
BREAK TIME! WOO!
ZendCon, October 2016 59
Other Helpful Commands
ZendCon, October 2016 60
Inspect a container
docker inspect [options] CONTAINER_NAME
• Returns a JSON string with data about the container
• Can also query
• docker inspect -f ā€œ{{ .NetworkSettings.IPAddress }}ā€ web_server
• Really handy for scripting out things like reverse proxies
ZendCon, October 2016 61
Work with images
• docker pull IMAGE – Pulls down an image before using
• docker images – Lists all the images that are downloaded
• docker rmi IMAGE – Deletes an image if it’s not being used
ZendCon, October 2016 62
Our Goals
• Not change our workflow (much)
• Run PHP 7, Unit Tests, and webserver
• Deploy ā€œeasilyā€
ZendCon, October 2016 63
Containerizing Commands
ZendCon, October 2016 64
Running Composer
docker run --rm 
-v c:/Users/drago/.composer:/root/.composer 
-v c:/Users/drago/Projects/workshop:/app 
-v c:/Users/drago/.ssh:/root/.ssh 
composer/composer 
require phpunit/phpunit
ZendCon, October 2016 65
Functions!
function docker-composer() {
appname=$(basename `pwd -P`)
appname="${appname/-/}"
imagename='composer/composer'
output=$(docker images | grep "${appname}_composer")
if [ "$?" = "0" ]; then
imagename="${appname}_composer"
fi
docker run --rm -v ~/.composer:/root/.composer -v
$(pwd):/app -v ~/.ssh:/root/.ssh $imagename $*
}
ZendCon, October 2016 66
Add our code to the autloader
{
"require": {
"phpunit/phpunit": "^5.5"
},
"autoload": {
"psr-4": {
"DemoApp": "src/"
}
}
}
ZendCon, October 2016 67
Run our app
docker run -d --name phptest 
-v c:/Users/drago/Projects/workshop/:/app 
-w /app/html 
-p 8080:80 
php:cli 
php -S 0.0.0.0:80
ZendCon, October 2016 68
Unit Test our Code
docker run --rm -ti 
-v c:/Users/drago/Projects/workshop/:/app
-w /app
php:cli
vendor/bin/phpunit -c phpunit.dist.xml
ZendCon, October 2016 69
Docker Compose
ZendCon, October 2016 70
What is Docker Compose?
• Multi-container orchestration
• A single config file holds all of your container info
• Works with Docker Swarm and a few other tools, like Rancher
ZendCon, October 2016 71
Sample docker-compose.yml
version: ā€˜2’
volumes:
mysqldata:
driver: local
phpserver:
build: ./docker/php
volumes:
- ./:/var/www/
mysqlserver:
image: mysql
environment:
MYSQL_DATABASE: dockerfordevs
MYSQL_ROOT_PASSWORD: docker
volumes:
- mysqldata:/var/lib/mysql
nginx:
build: ./docker/nginx
ports:
- "80:80"
- "443:443"
ZendCon, October 2016 72
Creating your own Images
ZendCon, October 2016 73
Dockerfile
• Dockerfile is the configuration steps for an image
• Can be created from scratch, or based on another image
• Allows you to add files, create default volumes, ports, etc
• Can be used privately or pushed to Docker Hub
ZendCon, October 2016 74
FROM php:7
RUN apt-get update 
&& apt-get install –y 
libmcrypt-dev 
libpng12-dev 
libfreetype6-dev 
libjpeg62-turbo-dev 
&& docker-php-ext-install iconv mcrypt pdo pdo_mysql
COPY build/app /var/www
# …
EXPOSE 80 443
VOLUME /var/www
VOLUME /var/log
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ZendCon, October 2016 75
Build it
docker build -t tag_name ./
• This runs through the Dockerfile and generates the image
• We can now use the tag name to run the image
ZendCon, October 2016 76
Add in some Compose
ZendCon, October 2016 77
Start the app with Compose
ZendCon, October 2016 78
Docker Machine
ZendCon, October 2016 79
What is Docker Machine?
• A provisioning tool that is used to set up a box with Docker
• Used in Docker Toolbox to create the VM
• Supports:
• EC2
• Azure
• Digital Ocean
• Hyper-V
• OpenStack
• Virtualbox
• VMWare
ZendCon, October 2016 80
Why use it?
• Makes it very easy to spin up new boxes
• Docker Machine handles all of the dirty stuff for you
• Docker Toolbox users are already using it
• Integrates with Docker Swarm
• It is not necessarily portable
ZendCon, October 2016 81
Let’s make a machine!
ZendCon, October 2016 82
Let’s Connect!
ZendCon, October 2016 83
Thank You!
• Software Engineer for InQuest
• Author of ā€œDocker for Developersā€
• https://leanpub.com/dockerfordevs
• Co-Host of ā€œJerks Talk Gamesā€
• http://jerkstalkgames
• http://ctankersley.com
• chris@ctankersley.com
• @dragonmantank
ZendCon, October 2016 84

More Related Content

What's hot (20)

PPTX
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Yevgeniy Brikman
Ā 
ODP
Docker for PHP Developers - Madison PHP 2017
Chris Tankersley
Ā 
PDF
Docker serverless v1.0
Thomas Chacko
Ā 
PDF
Docker.io
Ladislav Prskavec
Ā 
PPT
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Sematext Group, Inc.
Ā 
PPTX
TIAD 2016 : Application delivery in a container world
The Incredible Automation Day
Ā 
PPTX
Scaling Your App With Docker Swarm using Terraform, Packer on Openstack
Bobby DeVeaux, DevOps Consultant
Ā 
PDF
Docker Registry + Basic Auth
Remotty
Ā 
PDF
Ansible at work
Bas Meijer
Ā 
PDF
Real-Time Data Processing Pipeline & Visualization with Docker, Spark, Kafka ...
Roberto Hashioka
Ā 
PDF
Docker up and running
Victor S. Recio
Ā 
PDF
Docker Basics & Alfresco Content Services
Sujay Pillai
Ā 
PPTX
Scaling Development Environments with Docker
Docker, Inc.
Ā 
PPTX
HP Advanced Technology Group: Docker and Ansible
Patrick Galbraith
Ā 
PPTX
Reusable, composable, battle-tested Terraform modules
Yevgeniy Brikman
Ā 
PDF
Docker meetup - PaaS interoperability
Ludovic Piot
Ā 
PDF
ContainerDayVietnam2016: Django Development with Docker
Docker-Hanoi
Ā 
PPTX
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
CoreOS
Ā 
PPTX
Transforming Infrastructure into Code - Importing existing cloud resources u...
Shih Oon Liong
Ā 
PDF
Load Balancing Applications with NGINX in a CoreOS Cluster
Kevin Jones
Ā 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Yevgeniy Brikman
Ā 
Docker for PHP Developers - Madison PHP 2017
Chris Tankersley
Ā 
Docker serverless v1.0
Thomas Chacko
Ā 
Docker.io
Ladislav Prskavec
Ā 
Running High Performance and Fault Tolerant Elasticsearch Clusters on Docker
Sematext Group, Inc.
Ā 
TIAD 2016 : Application delivery in a container world
The Incredible Automation Day
Ā 
Scaling Your App With Docker Swarm using Terraform, Packer on Openstack
Bobby DeVeaux, DevOps Consultant
Ā 
Docker Registry + Basic Auth
Remotty
Ā 
Ansible at work
Bas Meijer
Ā 
Real-Time Data Processing Pipeline & Visualization with Docker, Spark, Kafka ...
Roberto Hashioka
Ā 
Docker up and running
Victor S. Recio
Ā 
Docker Basics & Alfresco Content Services
Sujay Pillai
Ā 
Scaling Development Environments with Docker
Docker, Inc.
Ā 
HP Advanced Technology Group: Docker and Ansible
Patrick Galbraith
Ā 
Reusable, composable, battle-tested Terraform modules
Yevgeniy Brikman
Ā 
Docker meetup - PaaS interoperability
Ludovic Piot
Ā 
ContainerDayVietnam2016: Django Development with Docker
Docker-Hanoi
Ā 
Tectonic Summit 2016: Kubernetes 1.5 and Beyond
CoreOS
Ā 
Transforming Infrastructure into Code - Importing existing cloud resources u...
Shih Oon Liong
Ā 
Load Balancing Applications with NGINX in a CoreOS Cluster
Kevin Jones
Ā 

Viewers also liked (20)

PDF
Especialidade de inclusão 5
GRUPO ESCOTEIRO JOƃO OSCALINO
Ā 
PPT
MockupBuilder
Lviv Startup Club
Ā 
PPTX
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley
Ā 
ODP
Git Workshop : Getting Started
Wildan Maulana
Ā 
PDF
Docker & PHP - Practical use case
rjsmelo
Ā 
DOCX
Spm file33
Poonam Singh
Ā 
PPTX
Introduction To Git Workshop
themystic_ca
Ā 
PPTX
Engine lab software hybrid cloud specialists
John Rowan
Ā 
PDF
Microservices without Servers
Dev_Events
Ā 
PPT
NTR Lab - bespoke software development in Russia
Olessya
Ā 
PPTX
Php development with Docker
Michael Bui
Ā 
PDF
2013 Social Admissions Report
Uversity, Inc.
Ā 
PPTX
Information Design Web Planning Mockup
ANGELA Smithers
Ā 
PPT
component based softwrae engineering Cbse
Sravs Dals
Ā 
PDF
Computer-free Website Development Demo - WordPressDC Jan 2015
Anthony D. Paul
Ā 
PDF
An introduction to contianers and Docker for PHP developers
Robert McFrazier
Ā 
PDF
Building Next Generation Applications and Microservices
Dev_Events
Ā 
PPTX
The App Evolution
Dev_Events
Ā 
PDF
Lab docker
Bruno Cornec
Ā 
PPTX
Documenting software architecture
Himanshu
Ā 
Especialidade de inclusão 5
GRUPO ESCOTEIRO JOƃO OSCALINO
Ā 
MockupBuilder
Lviv Startup Club
Ā 
Docker for Developers - PNWPHP 2016 Workshop
Chris Tankersley
Ā 
Git Workshop : Getting Started
Wildan Maulana
Ā 
Docker & PHP - Practical use case
rjsmelo
Ā 
Spm file33
Poonam Singh
Ā 
Introduction To Git Workshop
themystic_ca
Ā 
Engine lab software hybrid cloud specialists
John Rowan
Ā 
Microservices without Servers
Dev_Events
Ā 
NTR Lab - bespoke software development in Russia
Olessya
Ā 
Php development with Docker
Michael Bui
Ā 
2013 Social Admissions Report
Uversity, Inc.
Ā 
Information Design Web Planning Mockup
ANGELA Smithers
Ā 
component based softwrae engineering Cbse
Sravs Dals
Ā 
Computer-free Website Development Demo - WordPressDC Jan 2015
Anthony D. Paul
Ā 
An introduction to contianers and Docker for PHP developers
Robert McFrazier
Ā 
Building Next Generation Applications and Microservices
Dev_Events
Ā 
The App Evolution
Dev_Events
Ā 
Lab docker
Bruno Cornec
Ā 
Documenting software architecture
Himanshu
Ā 
Ad

Similar to Docker for PHP Developers - ZendCon 2016 (20)

ODP
Docker for PHP Developers - php[world] 2017
Chris Tankersley
Ā 
ODP
Docker for Developers
Chris Tankersley
Ā 
PDF
Dockerize your Symfony application - Symfony Live NYC 2014
André Rømcke
Ā 
PPTX
Docker for PHP Developers - Jetbrains
Chris Tankersley
Ā 
PDF
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Gaetano Giunta
Ā 
PDF
Preparing your dockerised application for production deployment
Dave Ward
Ā 
PDF
Killer Docker Workflows for Development
Chris Tankersley
Ā 
PDF
Developing and Deploying PHP with Docker
Patrick Mizer
Ā 
ODP
Docker for Developers - PHP Detroit 2018
Chris Tankersley
Ā 
PDF
ę™‚ä»£åœØč®Š Docker č¦ęœƒļ¼šå°åŒ— Docker 一旄兄門篇
Philip Zheng
Ā 
PDF
Accelerate your software development with Docker
Andrey Hristov
Ā 
PPTX
Accelerate your development with Docker
Andrey Hristov
Ā 
PPTX
Introduction to Docker
Alan Forbes
Ā 
PDF
Docker workshop 0507 Taichung
Paul Chao
Ā 
PDF
ę‰‹ęŠŠę‰‹åø¶ä½ å­ø Docker 兄門篇
Philip Zheng
Ā 
PDF
Faster and Easier Software Development using Docker Platform
msyukor
Ā 
PDF
Docker Essentials Workshop— Innovation Labs July 2020
CloudHero
Ā 
PPTX
Introduction to docker
Frederik Mogensen
Ā 
PDF
Docker for developers
sparkfabrik
Ā 
PDF
Docker for developers
DrupalDay
Ā 
Docker for PHP Developers - php[world] 2017
Chris Tankersley
Ā 
Docker for Developers
Chris Tankersley
Ā 
Dockerize your Symfony application - Symfony Live NYC 2014
André Rømcke
Ā 
Docker for PHP Developers - Jetbrains
Chris Tankersley
Ā 
eZ Publish 5: from zero to automated deployment (and no regressions!) in one ...
Gaetano Giunta
Ā 
Preparing your dockerised application for production deployment
Dave Ward
Ā 
Killer Docker Workflows for Development
Chris Tankersley
Ā 
Developing and Deploying PHP with Docker
Patrick Mizer
Ā 
Docker for Developers - PHP Detroit 2018
Chris Tankersley
Ā 
ę™‚ä»£åœØč®Š Docker č¦ęœƒļ¼šå°åŒ— Docker 一旄兄門篇
Philip Zheng
Ā 
Accelerate your software development with Docker
Andrey Hristov
Ā 
Accelerate your development with Docker
Andrey Hristov
Ā 
Introduction to Docker
Alan Forbes
Ā 
Docker workshop 0507 Taichung
Paul Chao
Ā 
ę‰‹ęŠŠę‰‹åø¶ä½ å­ø Docker 兄門篇
Philip Zheng
Ā 
Faster and Easier Software Development using Docker Platform
msyukor
Ā 
Docker Essentials Workshop— Innovation Labs July 2020
CloudHero
Ā 
Introduction to docker
Frederik Mogensen
Ā 
Docker for developers
sparkfabrik
Ā 
Docker for developers
DrupalDay
Ā 
Ad

More from Chris Tankersley (19)

PDF
8 Rules for Better Applications - PHP Tek 2025
Chris Tankersley
Ā 
PDF
The Art of API Design - PHP Tek 2025, Chris Tankersley
Chris Tankersley
Ā 
PDF
Docker is Dead: Long Live Containers
Chris Tankersley
Ā 
PDF
Bend time to your will with git
Chris Tankersley
Ā 
PDF
Using PHP Functions! (Not those functions, Google Cloud Functions)
Chris Tankersley
Ā 
PDF
Dead Simple APIs with OpenAPI
Chris Tankersley
Ā 
PDF
You Got Async in my PHP!
Chris Tankersley
Ā 
ODP
They are Watching You
Chris Tankersley
Ā 
ODP
BASHing at the CLI - Midwest PHP 2018
Chris Tankersley
Ā 
PDF
You Were Lied To About Optimization
Chris Tankersley
Ā 
ODP
Why Docker? Dayton PHP, April 2017
Chris Tankersley
Ā 
PPTX
OOP Is More Then Cars and Dogs - Midwest PHP 2017
Chris Tankersley
Ā 
PPTX
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley
Ā 
PPTX
How We Got Here: A Brief History of Open Source
Chris Tankersley
Ā 
PPTX
Oh Crap, My Code is Slow - Madison PHP 2016
Chris Tankersley
Ā 
PDF
A Brief History of Open Source
Chris Tankersley
Ā 
PPTX
Failing at Scale - PNWPHP 2016
Chris Tankersley
Ā 
PDF
Deploying Containers with Rancher
Chris Tankersley
Ā 
PDF
WTF Is Rancher?
Chris Tankersley
Ā 
8 Rules for Better Applications - PHP Tek 2025
Chris Tankersley
Ā 
The Art of API Design - PHP Tek 2025, Chris Tankersley
Chris Tankersley
Ā 
Docker is Dead: Long Live Containers
Chris Tankersley
Ā 
Bend time to your will with git
Chris Tankersley
Ā 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Chris Tankersley
Ā 
Dead Simple APIs with OpenAPI
Chris Tankersley
Ā 
You Got Async in my PHP!
Chris Tankersley
Ā 
They are Watching You
Chris Tankersley
Ā 
BASHing at the CLI - Midwest PHP 2018
Chris Tankersley
Ā 
You Were Lied To About Optimization
Chris Tankersley
Ā 
Why Docker? Dayton PHP, April 2017
Chris Tankersley
Ā 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
Chris Tankersley
Ā 
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley
Ā 
How We Got Here: A Brief History of Open Source
Chris Tankersley
Ā 
Oh Crap, My Code is Slow - Madison PHP 2016
Chris Tankersley
Ā 
A Brief History of Open Source
Chris Tankersley
Ā 
Failing at Scale - PNWPHP 2016
Chris Tankersley
Ā 
Deploying Containers with Rancher
Chris Tankersley
Ā 
WTF Is Rancher?
Chris Tankersley
Ā 

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
Ā 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
Ā 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
Ā 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
Ā 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
Ā 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
Ā 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
Ā 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
Ā 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
Ā 
PDF
July Patch Tuesday
Ivanti
Ā 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
Ā 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
Ā 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
Ā 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
Ā 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
Ā 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
Ā 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
Ā 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
Ā 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
Ā 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
Ā 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
Ā 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
Ā 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
Ā 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
Ā 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
Ā 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
Ā 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
Ā 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
Ā 
Smart Trailers 2025 Update with History and Overview
Paul Menig
Ā 
July Patch Tuesday
Ivanti
Ā 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
Ā 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
Ā 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
Ā 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
Ā 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
Ā 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
Ā 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
Ā 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
Ā 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
Ā 

Docker for PHP Developers - ZendCon 2016

  • 1. Docker for PHP Developers Chris Tankersley @dragonmantank ZendCon 2016, October 2016 ZendCon, October 2016 1
  • 2. What Is Docker? ā€œDocker is an open platform for developers and sysadmins to build, ship, and run distributed applications. Consisting of Docker Engine, a portable, lightweight runtime and packaging tool, and Docker Hub, a cloud service for sharing applications and automating workflows, Docker enables apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments.ā€ ZendCon, October 2016 2 https://www.docker.com/whatisdocker/
  • 4. Normal Bare-Metal Server ZendCon, October 2016 4 CPU RAM HD Network Operating System nginx PHP DB
  • 5. Virtual Machines ZendCon, October 2016 5 CPU RAM HD Network Operating System nginx PHP DB Operating System nginx PHP DB Operating System Hypervisor
  • 6. Containers ZendCon, October 2016 6 CPU RAM HD Network Operating System nginxnginx PHP DB PHP DB
  • 7. Containers Are Not New • LXC (Linux Containers) • OpenVZ • Systemd-nspawn • Qemu/kvm • BSD Jails • Solaris Zones • chroot ZendCon, October 2016 7
  • 8. Docker is an Ecosystem ZendCon, October 2016 8 Docker Engine
  • 9. Docker is an Ecosystem ZendCon, October 2016 9 Docker ComposeDocker Machine Docker Swarm
  • 10. How does it work? ZendCon, October 2016 10 Uses a variety of existing Container technologies Server Containers Hyper-V Containers xhyve Virtualization
  • 11. Sorry OSX < 10.10 and Windows < 10 Users Docker Toolbox ZendCon, October 2016 11
  • 13. Running a container • `docker run` will run a container • This will not restart an existing container, just create a new one • docker run [options] IMAGE [command] [arguments] • [options ]modify the docker process for this container • IMAGE is the image to use • [command] is the command to run inside the container • [arguments] are arguments for the command ZendCon, October 2016 13
  • 14. Running a simple shell ZendCon, October 2016 14
  • 15. Running a simple shell ZendCon, October 2016 15
  • 16. Running a simple shell ZendCon, October 2016 16
  • 17. What’s Going On? ZendCon, October 2016 17 Ubuntu Kernel / + bin/ + etc/ + dev/ + home/ + usr/ + var/ + lib/ + … nginx bash / + bin/ + etc/ + dev/ + home/ + usr/ + var/ + lib/ + … php
  • 26. Some Notes • All three containers are 100% self contained • Docker containers share common ancestors, but keep their own files • `docker run` parameters: • --rm – Destroy a container once it exits • -d – Run in the background (daemon mode) • -i – Run in interactive mode • --name – Give the container a name • -p [local port]:[container port] – Forward the local port to the container port ZendCon, October 2016 26
  • 28. Modifying a running container • `docker exec` can run a command inside of an existing container • Use Volumes to share data ZendCon, October 2016 28
  • 29. Persistent Data with Volumes • You can designate a volume with –v • Create a named volume with `volume create` • Volumes can be shared amongst containers • Volumes can mount data from the host system ZendCon, October 2016 29
  • 30. Mounting from the host machine ZendCon, October 2016 30
  • 31. Mounting from the host machine ZendCon, October 2016 31
  • 32. Mounting from the host machine ZendCon, October 2016 32
  • 33. Mounting from the host machine ZendCon, October 2016 33
  • 34. Mounting from the host machine ZendCon, October 2016 34
  • 35. Mounting from the host isn’t perfect • The container now has a window into your host machine • Permissions can get screwy if you are modifying in the container • Most things it creates will be root by default, and you probably aren’t root on the host machine • Host-mounted volumes are not portable at all • OSX and Hyper-V VMs have limited pathings to mount • OSX has poor I/O performance ZendCon, October 2016 35
  • 36. Named Data Volumes • Creates a space that becomes persistent • Can be mounted anywhere inside your images • Have our app containers use the data volume to store data • Use ā€˜editor containers’ to go in and modify data when needed ZendCon, October 2016 36
  • 43. Why go through the hassle? • Data volumes are portable, depending on the driver • Data volumes are safer • Separates the app containers from data • Production can use a data volume, dev can use a host volume • Our app containers stay small • Works directly with other tools ZendCon, October 2016 43
  • 45. Docker Links • Allows containers to ā€˜see’ each other over the network • Each container thinks the other one is just another machine • Containers all have an internal network address, so we don’t need to expose everything through the host • Legacy Links work with `--link` • Can set up virtual networks ZendCon, October 2016 45
  • 46. More Traditional Setup ZendCon, October 2016 46 INTARWEBS Nginx PHP-FPM Data Volume Port 9000 Editor
  • 53. Let’s Build It ZendCon, October 2016 53
  • 54. Let’s Build It ZendCon, October 2016 54
  • 55. Let’s Build It ZendCon, October 2016 55
  • 56. Let’s Build It ZendCon, October 2016 56
  • 57. Let’s Build It ZendCon, October 2016 57
  • 58. More Notes! • We can now rebuild sections of the app as needed • We can restart nginx without impacting PHP • We can extend much easier • Docker 1.12 has added a whole bunch of new stuff ZendCon, October 2016 58
  • 59. BREAK TIME! WOO! ZendCon, October 2016 59
  • 61. Inspect a container docker inspect [options] CONTAINER_NAME • Returns a JSON string with data about the container • Can also query • docker inspect -f ā€œ{{ .NetworkSettings.IPAddress }}ā€ web_server • Really handy for scripting out things like reverse proxies ZendCon, October 2016 61
  • 62. Work with images • docker pull IMAGE – Pulls down an image before using • docker images – Lists all the images that are downloaded • docker rmi IMAGE – Deletes an image if it’s not being used ZendCon, October 2016 62
  • 63. Our Goals • Not change our workflow (much) • Run PHP 7, Unit Tests, and webserver • Deploy ā€œeasilyā€ ZendCon, October 2016 63
  • 65. Running Composer docker run --rm -v c:/Users/drago/.composer:/root/.composer -v c:/Users/drago/Projects/workshop:/app -v c:/Users/drago/.ssh:/root/.ssh composer/composer require phpunit/phpunit ZendCon, October 2016 65
  • 66. Functions! function docker-composer() { appname=$(basename `pwd -P`) appname="${appname/-/}" imagename='composer/composer' output=$(docker images | grep "${appname}_composer") if [ "$?" = "0" ]; then imagename="${appname}_composer" fi docker run --rm -v ~/.composer:/root/.composer -v $(pwd):/app -v ~/.ssh:/root/.ssh $imagename $* } ZendCon, October 2016 66
  • 67. Add our code to the autloader { "require": { "phpunit/phpunit": "^5.5" }, "autoload": { "psr-4": { "DemoApp": "src/" } } } ZendCon, October 2016 67
  • 68. Run our app docker run -d --name phptest -v c:/Users/drago/Projects/workshop/:/app -w /app/html -p 8080:80 php:cli php -S 0.0.0.0:80 ZendCon, October 2016 68
  • 69. Unit Test our Code docker run --rm -ti -v c:/Users/drago/Projects/workshop/:/app -w /app php:cli vendor/bin/phpunit -c phpunit.dist.xml ZendCon, October 2016 69
  • 71. What is Docker Compose? • Multi-container orchestration • A single config file holds all of your container info • Works with Docker Swarm and a few other tools, like Rancher ZendCon, October 2016 71
  • 72. Sample docker-compose.yml version: ā€˜2’ volumes: mysqldata: driver: local phpserver: build: ./docker/php volumes: - ./:/var/www/ mysqlserver: image: mysql environment: MYSQL_DATABASE: dockerfordevs MYSQL_ROOT_PASSWORD: docker volumes: - mysqldata:/var/lib/mysql nginx: build: ./docker/nginx ports: - "80:80" - "443:443" ZendCon, October 2016 72
  • 73. Creating your own Images ZendCon, October 2016 73
  • 74. Dockerfile • Dockerfile is the configuration steps for an image • Can be created from scratch, or based on another image • Allows you to add files, create default volumes, ports, etc • Can be used privately or pushed to Docker Hub ZendCon, October 2016 74
  • 75. FROM php:7 RUN apt-get update && apt-get install –y libmcrypt-dev libpng12-dev libfreetype6-dev libjpeg62-turbo-dev && docker-php-ext-install iconv mcrypt pdo pdo_mysql COPY build/app /var/www # … EXPOSE 80 443 VOLUME /var/www VOLUME /var/log RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ZendCon, October 2016 75
  • 76. Build it docker build -t tag_name ./ • This runs through the Dockerfile and generates the image • We can now use the tag name to run the image ZendCon, October 2016 76
  • 77. Add in some Compose ZendCon, October 2016 77
  • 78. Start the app with Compose ZendCon, October 2016 78
  • 80. What is Docker Machine? • A provisioning tool that is used to set up a box with Docker • Used in Docker Toolbox to create the VM • Supports: • EC2 • Azure • Digital Ocean • Hyper-V • OpenStack • Virtualbox • VMWare ZendCon, October 2016 80
  • 81. Why use it? • Makes it very easy to spin up new boxes • Docker Machine handles all of the dirty stuff for you • Docker Toolbox users are already using it • Integrates with Docker Swarm • It is not necessarily portable ZendCon, October 2016 81
  • 82. Let’s make a machine! ZendCon, October 2016 82
  • 84. Thank You! • Software Engineer for InQuest • Author of ā€œDocker for Developersā€ • https://leanpub.com/dockerfordevs • Co-Host of ā€œJerks Talk Gamesā€ • http://jerkstalkgames • http://ctankersley.com • [email protected] • @dragonmantank ZendCon, October 2016 84