Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
From Docker to
Production
Chris Tankersley
@dragonmantank
ZendCon 2016, October 2016
ZendCon, October 2016 1
ZendCon, October 2016 2
Subliminal Advertisement
ZendCon, October 2016 3
ZendCon, October 2016 4
ZendCon, October 2016 5
ZendCon, October 2016 6
ZendCon, October 2016 7
ZendCon, October 2016 8
ZendCon, October 2016 9
Considerations
ZendCon, October 2016 10
How does your app handle storage?
ZendCon, October 2016 11
What does your build process look like?
ZendCon, October 2016 12
How well does your app handle scaling?
ZendCon, October 2016 13
Does it make sense?
ZendCon, October 2016 14
The Build Process
ZendCon, October 2016 15
Start Small
• Build your application
• Run composer
• Run npm/bower
• Build JS/CSS
• Use the compiled output to build an i...
docker build
• Additional options to look at
• -f, --file – Specify a different filename for the Dockerfile
• --no-cache –...
Sample usage
docker build 
--no-cache 
–f docker/php/phpserver.dockerfile 
–t prod_php /opt/builds/20161010
ZendCon, Octob...
phpserver.dockerfile
FROM php:fpm
RUN docker-php-ext-install pdo pdo_mysql
COPY ./ /var/www
ZendCon, October 2016 19
Docker Compose
ZendCon, October 2016 20
Very Good for Small Deployments
• Can be used to augment your dev environment
• Works well with Docker Machine
ZendCon, Oc...
Create a machine
docker-machine create --driver digitalocean 
--digital-ocean-access-token [token] 
zendcon2016
ZendCon, O...
ZendCon, October 2016 23
Switch to the remote node
• Run docker-machine env zendcon2016
& "C:Program
FilesDockerDockerResourcesbindocker-
machine.e...
Set up docker-compose
• Docker Compose allows multiple config files with -f
• Have a base docker-compose.yml for Productio...
version: '2'
volumes:
mysqldata:
driver: local
services:
nginx:
build:
context: ./
dockerfile: ./nginx.dockerfile
ports:
-...
version: '2'
volumes:
mysqldata:
driver: local
services:
nginx:
image: nginx
volumes:
- ./output_dev:/var/www/public:ro
- ...
When doing development
docker-compose 
–f docker-compose.yml 
–f docker-compose.dev.yml 
up -d
ZendCon, October 2016 28
When doing a deployment
docker-compose up -d
ZendCon, October 2016 29
Other Alternative – Variable Substitution
• Docker Compose allows variable substitution inside the file
• Wrap variables i...
When doing a deployment
docker build –f […] –t 20161010_php /opt/builds/20161010
DEPLOY_VERSION=20161010 docker-compose up...
Rancher
ZendCon, October 2016 32
Rancher and RancherOS
Daycamp 4 Developers - Ops for Devs 33
Manages your Containers
Daycamp 4 Developers - Ops for Devs 34
Manages your Hosts
Daycamp 4 Developers - Ops for Devs 35
Allows you to monitor containers
Daycamp 4 Developers - Ops for Devs 36
Allows you to manage your applications
Daycamp 4 Developers - Ops for Devs 37
Allows you to deploy your applications
Daycamp 4 Developers - Ops for Devs 38
Allows you to deploy your applications
Daycamp 4 Developers - Ops for Devs 39
Supports Docker Compose
Daycamp 4 Developers - Ops for Devs 40
Blue-Green Deployments
Daycamp 4 Developers - Ops for Devs 41
Router
App v1 App v2
Blue-Green Deployments
Daycamp 4 Developers - Ops for Devs 42
Router
App v3 App v2
Blue-Green Deployments
Daycamp 4 Developers - Ops for Devs 43
Router
App v3 App v2
Add rancher/server to the master
Daycamp 4 Developers - Ops for Devs 44
docker run -d 
--restart=always 
-p 8080:8080 
–na...
Add rancher/agent to nodes
Daycamp 4 Developers - Ops for Devs 45
docker run -d 
--privileged 
-v /var/run/docker.sock:/va...
All Done!
Daycamp 4 Developers - Ops for Devs 46
Deploying with Rancher CLI
Daycamp 4 Developers - Ops for Devs 47
What is it?
• Rancher has an API!
• Small executable that interacts with Rancher API
• Kind of like a custom docker-compos...
Get an API Key
Daycamp 4 Developers - Ops for Devs 49
Get an API Key
Daycamp 4 Developers - Ops for Devs 50
Download Rancher CLI
Daycamp 4 Developers - Ops for Devs 51
Export Stack Config
Daycamp 4 Developers - Ops for Devs 52
Two Config Files
Daycamp 4 Developers - Ops for Devs 53
docker-compose.yml
Daycamp 4 Developers - Ops for Devs 54
Deploy Script
Daycamp 4 Developers - Ops for Devs 55
ACCESS_KEY="C4F407CE1D8C59EB53BE"
SECRET="daNENHR241Jzm5Z9iw6VsujD9hW...
Edit and Deploy
Daycamp 4 Developers - Ops for Devs 56
Edit and Deploy
Daycamp 4 Developers - Ops for Devs 57
Finish Upgrade
Daycamp 4 Developers - Ops for Devs 58
Thank You!
• Software Engineer for InQuest
• Author of “Docker for Developers”
• https://leanpub.com/dockerfordevs
• Co-Ho...
Upcoming SlideShare
Loading in …5
×

From Docker to Production - ZendCon 2016

238 views

Published on

Congrats! You and your coworkers love Docker. Docker has become an increasingly helpful tool when it comes to DevOps. We can now build smaller, more robust local development setups with the promise of mirroring production. One thing that still plagues many situations is how to get those containers into production and update them over time. We'll explore different tools for setting up, configuring, and maintaining containers as they go live.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

From Docker to Production - ZendCon 2016

  1. 1. From Docker to Production Chris Tankersley @dragonmantank ZendCon 2016, October 2016 ZendCon, October 2016 1
  2. 2. ZendCon, October 2016 2
  3. 3. Subliminal Advertisement ZendCon, October 2016 3
  4. 4. ZendCon, October 2016 4
  5. 5. ZendCon, October 2016 5
  6. 6. ZendCon, October 2016 6
  7. 7. ZendCon, October 2016 7
  8. 8. ZendCon, October 2016 8
  9. 9. ZendCon, October 2016 9
  10. 10. Considerations ZendCon, October 2016 10
  11. 11. How does your app handle storage? ZendCon, October 2016 11
  12. 12. What does your build process look like? ZendCon, October 2016 12
  13. 13. How well does your app handle scaling? ZendCon, October 2016 13
  14. 14. Does it make sense? ZendCon, October 2016 14
  15. 15. The Build Process ZendCon, October 2016 15
  16. 16. Start Small • Build your application • Run composer • Run npm/bower • Build JS/CSS • Use the compiled output to build an image with docker build • Push full image to private registry ZendCon, October 2016 16
  17. 17. docker build • Additional options to look at • -f, --file – Specify a different filename for the Dockerfile • --no-cache – Don’t use a cached layer • --pull – Always pull a new version of the image ZendCon, October 2016 17
  18. 18. Sample usage docker build --no-cache –f docker/php/phpserver.dockerfile –t prod_php /opt/builds/20161010 ZendCon, October 2016 18
  19. 19. phpserver.dockerfile FROM php:fpm RUN docker-php-ext-install pdo pdo_mysql COPY ./ /var/www ZendCon, October 2016 19
  20. 20. Docker Compose ZendCon, October 2016 20
  21. 21. Very Good for Small Deployments • Can be used to augment your dev environment • Works well with Docker Machine ZendCon, October 2016 21
  22. 22. Create a machine docker-machine create --driver digitalocean --digital-ocean-access-token [token] zendcon2016 ZendCon, October 2016 22
  23. 23. ZendCon, October 2016 23
  24. 24. Switch to the remote node • Run docker-machine env zendcon2016 & "C:Program FilesDockerDockerResourcesbindocker- machine.exe" env zendcon2016 | Invoke-Expression ZendCon, October 2016 24
  25. 25. Set up docker-compose • Docker Compose allows multiple config files with -f • Have a base docker-compose.yml for Production • Add a secondary one for Development ZendCon, October 2016 25
  26. 26. version: '2' volumes: mysqldata: driver: local services: nginx: build: context: ./ dockerfile: ./nginx.dockerfile ports: - 80:80 - 443:443 phpserver: build: context: ./ dockerfile: ./phpserver.dockerfile working_dir: /var/www/public mysqlserver: image: mysql environment: [redacted] volumes: - mysqldata:/var/lib/mysql ZendCon, October 2016 26 docker-compose.yml
  27. 27. version: '2' volumes: mysqldata: driver: local services: nginx: image: nginx volumes: - ./output_dev:/var/www/public:ro - ./app/nginx/default.conf:/etc/nginx/conf.d/default.conf - ./ssl:/etc/nginx/ssl/ phpserver: build: context: ./ dockerfile: ./phpserver.dockerfile working_dir: /var/www/public volumes: - ./app:/var/www/ - ./vendor:/var/www/vendor mysqlserver: image: mysql environment: [redacted] volumes: - mysqldata:/var/lib/mysql ZendCon, October 2016 27 docker-compose.dev.yml
  28. 28. When doing development docker-compose –f docker-compose.yml –f docker-compose.dev.yml up -d ZendCon, October 2016 28
  29. 29. When doing a deployment docker-compose up -d ZendCon, October 2016 29
  30. 30. Other Alternative – Variable Substitution • Docker Compose allows variable substitution inside the file • Wrap variables in ${} • image: ${DEPLOY_VERSION}_php ZendCon, October 2016 30
  31. 31. When doing a deployment docker build –f […] –t 20161010_php /opt/builds/20161010 DEPLOY_VERSION=20161010 docker-compose up -d ZendCon, October 2016 31
  32. 32. Rancher ZendCon, October 2016 32
  33. 33. Rancher and RancherOS Daycamp 4 Developers - Ops for Devs 33
  34. 34. Manages your Containers Daycamp 4 Developers - Ops for Devs 34
  35. 35. Manages your Hosts Daycamp 4 Developers - Ops for Devs 35
  36. 36. Allows you to monitor containers Daycamp 4 Developers - Ops for Devs 36
  37. 37. Allows you to manage your applications Daycamp 4 Developers - Ops for Devs 37
  38. 38. Allows you to deploy your applications Daycamp 4 Developers - Ops for Devs 38
  39. 39. Allows you to deploy your applications Daycamp 4 Developers - Ops for Devs 39
  40. 40. Supports Docker Compose Daycamp 4 Developers - Ops for Devs 40
  41. 41. Blue-Green Deployments Daycamp 4 Developers - Ops for Devs 41 Router App v1 App v2
  42. 42. Blue-Green Deployments Daycamp 4 Developers - Ops for Devs 42 Router App v3 App v2
  43. 43. Blue-Green Deployments Daycamp 4 Developers - Ops for Devs 43 Router App v3 App v2
  44. 44. Add rancher/server to the master Daycamp 4 Developers - Ops for Devs 44 docker run -d --restart=always -p 8080:8080 –name=rancher rancher/server
  45. 45. Add rancher/agent to nodes Daycamp 4 Developers - Ops for Devs 45 docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock rancher/agent:v0.7.9 http://192.168.99.100:8080/v1/scripts/[hash]
  46. 46. All Done! Daycamp 4 Developers - Ops for Devs 46
  47. 47. Deploying with Rancher CLI Daycamp 4 Developers - Ops for Devs 47
  48. 48. What is it? • Rancher has an API! • Small executable that interacts with Rancher API • Kind of like a custom docker-compose Daycamp 4 Developers - Ops for Devs 48
  49. 49. Get an API Key Daycamp 4 Developers - Ops for Devs 49
  50. 50. Get an API Key Daycamp 4 Developers - Ops for Devs 50
  51. 51. Download Rancher CLI Daycamp 4 Developers - Ops for Devs 51
  52. 52. Export Stack Config Daycamp 4 Developers - Ops for Devs 52
  53. 53. Two Config Files Daycamp 4 Developers - Ops for Devs 53
  54. 54. docker-compose.yml Daycamp 4 Developers - Ops for Devs 54
  55. 55. Deploy Script Daycamp 4 Developers - Ops for Devs 55 ACCESS_KEY="C4F407CE1D8C59EB53BE" SECRET="daNENHR241Jzm5Z9iw6VsujD9hWfjHWrDzkKmKiA" RANCHER_URL="http://192.168.99.100:8080" ./rancher-compose --secret-key=${SECRET} --access-key=${ACCESS_KEY} --url=${RANCHER_URL} -- file=docker-compose.yml --rancher-file=rancher-compose.yml -p phptest up --upgrade -d
  56. 56. Edit and Deploy Daycamp 4 Developers - Ops for Devs 56
  57. 57. Edit and Deploy Daycamp 4 Developers - Ops for Devs 57
  58. 58. Finish Upgrade Daycamp 4 Developers - Ops for Devs 58
  59. 59. 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 59

×