Date post: | 12-Jan-2017 |
Category: |
Technology |
Upload: | chris-tankersley |
View: | 116 times |
Download: | 0 times |
ZendCon, October 2016 1
From Docker to ProductionChris Tankersley@dragonmantankZendCon 2016, October 2016
ZendCon, October 2016 2
ZendCon, October 2016 3
Subliminal Advertisement
ZendCon, October 2016 4
ZendCon, October 2016 5
ZendCon, October 2016 6
ZendCon, October 2016 7
ZendCon, October 2016 8
ZendCon, October 2016 9
ZendCon, October 2016 10
Considerations
ZendCon, October 2016 11
How does your app handle storage?
ZendCon, October 2016 12
What does your build process look like?
ZendCon, October 2016 13
How well does your app handle scaling?
ZendCon, October 2016 14
Does it make sense?
ZendCon, October 2016 15
The Build Process
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
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
ZendCon, October 2016 18
Sample usagedocker build \ --no-cache \ –f docker/php/phpserver.dockerfile \ –t prod_php /opt/builds/20161010
ZendCon, October 2016 19
phpserver.dockerfileFROM php:fpmRUN docker-php-ext-install pdo pdo_mysqlCOPY ./ /var/www
ZendCon, October 2016 20
Docker Compose
ZendCon, October 2016 21
Very Good for Small Deployments• Can be used to augment your dev environment• Works well with Docker Machine
ZendCon, October 2016 22
Create a machinedocker-machine create --driver digitalocean \ --digital-ocean-access-token [token] \ zendcon2016
ZendCon, October 2016 23
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
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
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
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
ZendCon, October 2016 28
When doing developmentdocker-compose \ –f docker-compose.yml \ –f docker-compose.dev.yml \ up -d
ZendCon, October 2016 29
When doing a deploymentdocker-compose up -d
ZendCon, October 2016 30
Other Alternative – Variable Substitution• Docker Compose allows variable substitution inside the file• Wrap variables in ${}• image: ${DEPLOY_VERSION}_php
ZendCon, October 2016 31
When doing a deploymentdocker build –f […] –t 20161010_php /opt/builds/20161010DEPLOY_VERSION=20161010 docker-compose up -d
ZendCon, October 2016 32
Rancher
Daycamp 4 Developers - Ops for Devs 33
Rancher and RancherOS
Daycamp 4 Developers - Ops for Devs 34
Manages your Containers
Daycamp 4 Developers - Ops for Devs 35
Manages your Hosts
Daycamp 4 Developers - Ops for Devs 36
Allows you to monitor containers
Daycamp 4 Developers - Ops for Devs 37
Allows you to manage your applications
Daycamp 4 Developers - Ops for Devs 38
Allows you to deploy your applications
Daycamp 4 Developers - Ops for Devs 39
Allows you to deploy your applications
Daycamp 4 Developers - Ops for Devs 40
Supports Docker Compose
Daycamp 4 Developers - Ops for Devs 41
Blue-Green Deployments
Router
App v1 App v2
Daycamp 4 Developers - Ops for Devs 42
Blue-Green Deployments
Router
App v3 App v2
Daycamp 4 Developers - Ops for Devs 43
Blue-Green Deployments
Router
App v3 App v2
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
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]
Daycamp 4 Developers - Ops for Devs 46
All Done!
Daycamp 4 Developers - Ops for Devs 47
Deploying with Rancher CLI
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
Daycamp 4 Developers - Ops for Devs 49
Get an API Key
Daycamp 4 Developers - Ops for Devs 50
Get an API Key
Daycamp 4 Developers - Ops for Devs 51
Download Rancher CLI
Daycamp 4 Developers - Ops for Devs 52
Export Stack Config
Daycamp 4 Developers - Ops for Devs 53
Two Config Files
Daycamp 4 Developers - Ops for Devs 54
docker-compose.yml
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
Daycamp 4 Developers - Ops for Devs 56
Edit and Deploy
Daycamp 4 Developers - Ops for Devs 57
Edit and Deploy
Daycamp 4 Developers - Ops for Devs 58
Finish Upgrade
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