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.
Converting Your Dev Environment
to a Docker Stack
Dana Luther
https://joind.in/talk/ab10a
https://github.com/DanaLuther/De...
Consolidated Work Stack
Friend A
PHP 5.6
Apache
MySQL
Cause B
PHP 7.1 FPM
NGINX
MySQL
PHP 7.0 FPM
NGINX
MySQL
Licensed
Application
Client D
PHP 7.1 FPM
NGINX
MySQL 5.3
Client C
PHP 5.6 FPM
NGINX
MySQL 5.2
PHP 5.6
Apache
MySQL 5.3
Cl...
THERE IS A
BETTER
WAY
VM
PHP 7.0 FPM
NGINX
MySQL
So, how does that work???
🤔
?
? ?
?
docker-compose.yml
Docker Compose Version
Services in the Stack
Configurations,
Secrets,
Storage Volumes,
etc.
Version: “3....
SIDEBAR:The Docker Hierarchy
Image Container Service Stack
Node Swarm
> docker stack deploy …
Swarm
NODE 1
NODE 2
ETC.
PHP 1 MySQL
NGINX PHP 2
SIDEBAR:Docker Command Syntax
docker (object) (action) (args)
> docker container ls
> docker image ls
> docker service ls
...
The swarm …
Node
Manager
Node
Worker
Node
Worker
Node
Worker
Node
Manager
A SWARM OF ONE
> docker swarm init
⚠ Common “Gotcha”
Swarm init — ONE TIME ONLY
* THE SWARM PERSISTS *
> docker swarm leave
> docker swarm leave —force
POPQUIZ! A. What’s the difference
between a container and a
service?
B. What’s the difference
between a service and a
stack?
Commonly Useful Images:
mysql
php
nginx
httpd
node
redis
wordpress
composer
memcached
alpine
postgres
busybox
phpmyadmin/p...
Images for Automated Testing
selenium/standalone-chrome-debug
selenium/standalone-firefox-debug:2.53.0
acceptance.suite.yml...
SIDEBAR:Legacy images, containers, volumes
> docker image prune
> docker container prune
> docker (whatever) prune
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
SIDEBAR:LABELS — use them everywhere!
🤔
?
? ?
? The -f toggle
-f name=vm_php
-f label=com.envisage.desc=php
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
Volume Example for php
php:
volumes:
- ./public_html:/var/ www/html
Local path relative
to the file
Path location within
th...
Using named storage volumes
Volumes:
pub_html:
external: true
…
php:
volumes:
- pub_html:/var/ www/html
Volume name
Path l...
⚠ Common “Gotcha”
* BEWARE WINDOWS PATHS *
C:DockerDriveSite
/C/DockerDrives/Site
/host_mnt/c/DockerDrives/Site
//c/Docker...
POPQUIZ! A. What is the command to
initialize a swarm?
B. What is the command to
deploy a docker stack?
> docker stack deploy -c docker-compose.yml vm
🤔
?
? ?
?
> docker service ls
> docker stack ps vm
> docker service logs vm_db
Want to see it in action?
> docker service logs vm_nginx -f
⚠ Common “Gotcha”
localhost:3306 db:3306
upstream fastcgi {
server 127.0.0.1:9000
}
upstream fastcgi {
server php:9000
}
Ok, great! But … 	 ¯_(ツ)_/¯
My production server
has lots of configurations
that have been customized…
php/conf.d/*
my.cnf
...
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
Config: mysite
> docker config inspect vm_mysite
version: “3.4”
services:
nginx:
image: nginx
networks:
- web
deploy:
replicas: 1
restart_policy:
condition: on-failure
lab...
Secret: db_pwd
> docker secret inspect zcoe_db_pwd
⚠ Common “Gotcha”
> docker config create mysite.2 ./mysite.conf
> docker service update —config-rm vm_mysite 
—config-add ...
Done with the project for now?
> docker stack rm vm
POPQUIZ! A. How do you check the
replication status of services?
B. How do you check for error
messages on the stack?
> do...
Same project … multiple production
targets?
docker-compose.yml
docker-compose-clientA.yml
docker-compose-clientB.yml
POPQUIZ! A. How do you filter a list of
docker objects (services,
containers, images, etc)
SIDEBAR:The $( ) magic with -q -l -f
-q Quiet (ID only)
-l Last Updated Only (1 result)
-f Filter (you remember this)
> do...
Converting your DEV Environment to a Docker Stack - ZCOE18
Converting your DEV Environment to a Docker Stack - ZCOE18
Converting your DEV Environment to a Docker Stack - ZCOE18
Upcoming SlideShare
Loading in …5
×

of

Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 1 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 2 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 3 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 4 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 5 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 6 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 7 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 8 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 9 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 10 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 11 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 12 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 13 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 14 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 15 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 16 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 17 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 18 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 19 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 20 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 21 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 22 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 23 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 24 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 25 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 26 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 27 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 28 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 29 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 30 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 31 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 32 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 33 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 34 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 35 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 36 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 37 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 38 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 39 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 40 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 41 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 42 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 43 Converting your DEV Environment to a Docker Stack - ZCOE18 Slide 44
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

1 Like

Share

Download to read offline

Converting your DEV Environment to a Docker Stack - ZCOE18

Download to read offline

Heard a lot about Docker but not sure where to start? In this presentation, we will go over the simplest ways to convert your development environment over to a Docker stack, including support for full acceptance testing with Selenium. We’ll then go over how to modify the stack to mimic your production/pre-production environment(s) as closely as possible, and demystify working with the containers in the stack.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Converting your DEV Environment to a Docker Stack - ZCOE18

  1. 1. Converting Your Dev Environment to a Docker Stack Dana Luther https://joind.in/talk/ab10a https://github.com/DanaLuther/DevDockerStackSampleZCOE
  2. 2. Consolidated Work Stack Friend A PHP 5.6 Apache MySQL Cause B PHP 7.1 FPM NGINX MySQL PHP 7.0 FPM NGINX MySQL
  3. 3. Licensed Application Client D PHP 7.1 FPM NGINX MySQL 5.3 Client C PHP 5.6 FPM NGINX MySQL 5.2 PHP 5.6 Apache MySQL 5.3 Client A Client B PHP 7.1 Apache MySQL 5.4
  4. 4. THERE IS A BETTER WAY
  5. 5. VM PHP 7.0 FPM NGINX MySQL
  6. 6. So, how does that work??? 🤔 ? ? ? ?
  7. 7. docker-compose.yml Docker Compose Version Services in the Stack Configurations, Secrets, Storage Volumes, etc. Version: “3.4” services: nginx: image: nginx command: [ 'sh', '-c', "exec nginx -g 'daemon off;'" ] … php: image: php:7.2-fpm … network: web_frontend config: nginx.conf: file: ./nginx/nginx.conf volumes: …https://docs.docker.com/compose/compose-file/
  8. 8. SIDEBAR:The Docker Hierarchy Image Container Service Stack Node Swarm
  9. 9. > docker stack deploy … Swarm NODE 1 NODE 2 ETC. PHP 1 MySQL NGINX PHP 2
  10. 10. SIDEBAR:Docker Command Syntax docker (object) (action) (args) > docker container ls > docker image ls > docker service ls > docker volume ls image container stack service config network node plugin swarm Objects ls ps prune inspect create remove / rm Common Actions
  11. 11. The swarm … Node Manager Node Worker Node Worker Node Worker
  12. 12. Node Manager A SWARM OF ONE > docker swarm init
  13. 13. ⚠ Common “Gotcha” Swarm init — ONE TIME ONLY * THE SWARM PERSISTS * > docker swarm leave > docker swarm leave —force
  14. 14. POPQUIZ! A. What’s the difference between a container and a service? B. What’s the difference between a service and a stack?
  15. 15. Commonly Useful Images: mysql php nginx httpd node redis wordpress composer memcached alpine postgres busybox phpmyadmin/phpmyadmin https://store.docker.com > docker image pull mysql:latest BONUS POP QUIZ! How do you pull an image manually?
  16. 16. Images for Automated Testing selenium/standalone-chrome-debug selenium/standalone-firefox-debug:2.53.0 acceptance.suite.yml docker-compose.yml
  17. 17. SIDEBAR:Legacy images, containers, volumes > docker image prune > docker container prune > docker (whatever) prune
  18. 18. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  19. 19. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  20. 20. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  21. 21. SIDEBAR:LABELS — use them everywhere! 🤔 ? ? ? ? The -f toggle -f name=vm_php -f label=com.envisage.desc=php
  22. 22. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  23. 23. Volume Example for php php: volumes: - ./public_html:/var/ www/html Local path relative to the file Path location within the container
  24. 24. Using named storage volumes Volumes: pub_html: external: true … php: volumes: - pub_html:/var/ www/html Volume name Path location within the container > docker volume create pub_html / —opt type=none / —opt o=bind / —opt device=/Volumes/E/site/ —label “com.envisage.desc=Site”
  25. 25. ⚠ Common “Gotcha” * BEWARE WINDOWS PATHS * C:DockerDriveSite /C/DockerDrives/Site /host_mnt/c/DockerDrives/Site //c/DockerDrives/Site Windows LCOW Volume Path
  26. 26. POPQUIZ! A. What is the command to initialize a swarm? B. What is the command to deploy a docker stack?
  27. 27. > docker stack deploy -c docker-compose.yml vm 🤔 ? ? ? ? > docker service ls > docker stack ps vm
  28. 28. > docker service logs vm_db
  29. 29. Want to see it in action? > docker service logs vm_nginx -f
  30. 30. ⚠ Common “Gotcha” localhost:3306 db:3306 upstream fastcgi { server 127.0.0.1:9000 } upstream fastcgi { server php:9000 }
  31. 31. Ok, great! But … ¯_(ツ)_/¯ My production server has lots of configurations that have been customized… php/conf.d/* my.cnf nginx.conf nginx/conf.d/*
  32. 32. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  33. 33. Config: mysite > docker config inspect vm_mysite
  34. 34. version: “3.4” services: nginx: image: nginx networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “Nginx Service” volumes: - ./public_html:/var/ www/html configs: - source: mysite target: /etc/nginx/conf.d/mysite.conf ports: - “80:80” - “443:443” depends_on: - php - db labels: com.envisageinternational.desc: “Nginx Container” command: [‘sh’,'-c',"exec nginx -g 'daemon off;’”] db: image: mysql ports: - “3306:3306” networks: - web secrets: - db_pwd deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [ node.role == manager ] environment: - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db_pwd php: image: php:7.0-fpm networks: - web depends_on: - db deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-FPM Service” ports: - “9000:9000” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-FPM Container” php-cli: image: php:7.0-cli networks: - web deploy: replicas: 1 restart_policy: condition: on-failure labels: com.envisageinternational.desc: “PHP-CLI Service” volumes: - ./public_html:/var/ www/html labels: com.envisageinternational.desc: “PHP-CLI Container” command: [‘bin/sh’, ‘-c’, “sleep infinity”] networks: web: configs: mysite: file: ./mysite.conf secrets: db_pwd: file: ./root_db_password.txt PHP 7.0 FPM NGINX MySQL
  35. 35. Secret: db_pwd > docker secret inspect zcoe_db_pwd
  36. 36. ⚠ Common “Gotcha” > docker config create mysite.2 ./mysite.conf > docker service update —config-rm vm_mysite —config-add source:mysite.2,target=/etc/nginx/default.conf vm_nginx > docker config ls
  37. 37. Done with the project for now? > docker stack rm vm
  38. 38. POPQUIZ! A. How do you check the replication status of services? B. How do you check for error messages on the stack? > docker stack ps vm —no-trunc BONUS POINT How do you avoid truncating the error message?
  39. 39. Same project … multiple production targets? docker-compose.yml docker-compose-clientA.yml docker-compose-clientB.yml
  40. 40. POPQUIZ! A. How do you filter a list of docker objects (services, containers, images, etc)
  41. 41. SIDEBAR:The $( ) magic with -q -l -f -q Quiet (ID only) -l Last Updated Only (1 result) -f Filter (you remember this) > docker container ls -q -l > docker container exec -it $(docker ps -q -l -f name=vm_web) bash
  • shanghosh2004

    Oct. 21, 2018

Heard a lot about Docker but not sure where to start? In this presentation, we will go over the simplest ways to convert your development environment over to a Docker stack, including support for full acceptance testing with Selenium. We’ll then go over how to modify the stack to mimic your production/pre-production environment(s) as closely as possible, and demystify working with the containers in the stack.

Views

Total views

205

On Slideshare

0

From embeds

0

Number of embeds

2

Actions

Downloads

4

Shares

0

Comments

0

Likes

1

×