From Docker to Production - ZendCon 2016
-
Upload
chris-tankersley -
Category
Technology
-
view
120 -
download
0
Transcript of From Docker to Production - ZendCon 2016
![Page 1: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/1.jpg)
ZendCon, October 2016 1
From Docker to ProductionChris Tankersley@dragonmantankZendCon 2016, October 2016
![Page 2: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/2.jpg)
ZendCon, October 2016 2
![Page 3: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/3.jpg)
ZendCon, October 2016 3
Subliminal Advertisement
![Page 4: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/4.jpg)
ZendCon, October 2016 4
![Page 5: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/5.jpg)
ZendCon, October 2016 5
![Page 6: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/6.jpg)
ZendCon, October 2016 6
![Page 7: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/7.jpg)
ZendCon, October 2016 7
![Page 8: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/8.jpg)
ZendCon, October 2016 8
![Page 9: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/9.jpg)
ZendCon, October 2016 9
![Page 10: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/10.jpg)
ZendCon, October 2016 10
Considerations
![Page 11: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/11.jpg)
ZendCon, October 2016 11
How does your app handle storage?
![Page 12: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/12.jpg)
ZendCon, October 2016 12
What does your build process look like?
![Page 13: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/13.jpg)
ZendCon, October 2016 13
How well does your app handle scaling?
![Page 14: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/14.jpg)
ZendCon, October 2016 14
Does it make sense?
![Page 15: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/15.jpg)
ZendCon, October 2016 15
The Build Process
![Page 16: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/16.jpg)
ZendCon, October 2016 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
![Page 17: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/17.jpg)
ZendCon, October 2016 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
![Page 18: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/18.jpg)
ZendCon, October 2016 18
Sample usagedocker build \ --no-cache \ –f docker/php/phpserver.dockerfile \ –t prod_php /opt/builds/20161010
![Page 19: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/19.jpg)
ZendCon, October 2016 19
phpserver.dockerfileFROM php:fpmRUN docker-php-ext-install pdo pdo_mysqlCOPY ./ /var/www
![Page 20: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/20.jpg)
ZendCon, October 2016 20
Docker Compose
![Page 21: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/21.jpg)
ZendCon, October 2016 21
Very Good for Small Deployments• Can be used to augment your dev environment• Works well with Docker Machine
![Page 22: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/22.jpg)
ZendCon, October 2016 22
Create a machinedocker-machine create --driver digitalocean \ --digital-ocean-access-token [token] \ zendcon2016
![Page 23: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/23.jpg)
ZendCon, October 2016 23
![Page 24: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/24.jpg)
ZendCon, October 2016 24
Switch to the remote node• Run docker-machine env zendcon2016
& "C:\Program Files\Docker\Docker\Resources\bin\docker-machine.exe" env zendcon2016 | Invoke-Expression
![Page 25: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/25.jpg)
ZendCon, October 2016 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
![Page 26: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/26.jpg)
ZendCon, October 2016 26
version: '2'volumes: mysqldata: driver: localservices: 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
docker-compose.yml
![Page 27: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/27.jpg)
ZendCon, October 2016 27
version: '2'volumes: mysqldata: driver: localservices: 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
docker-compose.dev.yml
![Page 28: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/28.jpg)
ZendCon, October 2016 28
When doing developmentdocker-compose \ –f docker-compose.yml \ –f docker-compose.dev.yml \ up -d
![Page 29: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/29.jpg)
ZendCon, October 2016 29
When doing a deploymentdocker-compose up -d
![Page 30: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/30.jpg)
ZendCon, October 2016 30
Other Alternative – Variable Substitution• Docker Compose allows variable substitution inside the file• Wrap variables in ${}• image: ${DEPLOY_VERSION}_php
![Page 31: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/31.jpg)
ZendCon, October 2016 31
When doing a deploymentdocker build –f […] –t 20161010_php /opt/builds/20161010DEPLOY_VERSION=20161010 docker-compose up -d
![Page 32: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/32.jpg)
ZendCon, October 2016 32
Rancher
![Page 33: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/33.jpg)
Daycamp 4 Developers - Ops for Devs 33
Rancher and RancherOS
![Page 34: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/34.jpg)
Daycamp 4 Developers - Ops for Devs 34
Manages your Containers
![Page 35: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/35.jpg)
Daycamp 4 Developers - Ops for Devs 35
Manages your Hosts
![Page 36: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/36.jpg)
Daycamp 4 Developers - Ops for Devs 36
Allows you to monitor containers
![Page 37: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/37.jpg)
Daycamp 4 Developers - Ops for Devs 37
Allows you to manage your applications
![Page 38: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/38.jpg)
Daycamp 4 Developers - Ops for Devs 38
Allows you to deploy your applications
![Page 39: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/39.jpg)
Daycamp 4 Developers - Ops for Devs 39
Allows you to deploy your applications
![Page 40: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/40.jpg)
Daycamp 4 Developers - Ops for Devs 40
Supports Docker Compose
![Page 41: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/41.jpg)
Daycamp 4 Developers - Ops for Devs 41
Blue-Green Deployments
Router
App v1 App v2
![Page 42: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/42.jpg)
Daycamp 4 Developers - Ops for Devs 42
Blue-Green Deployments
Router
App v3 App v2
![Page 43: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/43.jpg)
Daycamp 4 Developers - Ops for Devs 43
Blue-Green Deployments
Router
App v3 App v2
![Page 44: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/44.jpg)
Daycamp 4 Developers - Ops for Devs 44
Add rancher/server to the master
docker run -d \ --restart=always \ -p 8080:8080 \ –name=rancher \ rancher/server
![Page 45: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/45.jpg)
Daycamp 4 Developers - Ops for Devs 45
Add rancher/agent to nodes
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]
![Page 46: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/46.jpg)
Daycamp 4 Developers - Ops for Devs 46
All Done!
![Page 47: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/47.jpg)
Daycamp 4 Developers - Ops for Devs 47
Deploying with Rancher CLI
![Page 48: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/48.jpg)
Daycamp 4 Developers - Ops for Devs 48
What is it?• Rancher has an API!• Small executable that interacts with Rancher API• Kind of like a custom docker-compose
![Page 49: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/49.jpg)
Daycamp 4 Developers - Ops for Devs 49
Get an API Key
![Page 50: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/50.jpg)
Daycamp 4 Developers - Ops for Devs 50
Get an API Key
![Page 51: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/51.jpg)
Daycamp 4 Developers - Ops for Devs 51
Download Rancher CLI
![Page 52: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/52.jpg)
Daycamp 4 Developers - Ops for Devs 52
Export Stack Config
![Page 53: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/53.jpg)
Daycamp 4 Developers - Ops for Devs 53
Two Config Files
![Page 54: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/54.jpg)
Daycamp 4 Developers - Ops for Devs 54
docker-compose.yml
![Page 55: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/55.jpg)
Daycamp 4 Developers - Ops for Devs 55
Deploy ScriptACCESS_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
![Page 56: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/56.jpg)
Daycamp 4 Developers - Ops for Devs 56
Edit and Deploy
![Page 57: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/57.jpg)
Daycamp 4 Developers - Ops for Devs 57
Edit and Deploy
![Page 58: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/58.jpg)
Daycamp 4 Developers - Ops for Devs 58
Finish Upgrade
![Page 59: From Docker to Production - ZendCon 2016](https://reader036.fdocuments.in/reader036/viewer/2022062400/5876fde21a28abf3398b6b61/html5/thumbnails/59.jpg)
ZendCon, October 2016 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• [email protected]• @dragonmantank