Why Docker? Dayton PHP, April 2017
-
Upload
chris-tankersley -
Category
Technology
-
view
137 -
download
0
Transcript of Why Docker? Dayton PHP, April 2017
![Page 1: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/1.jpg)
Why Docker?
Chris Tankersley
@dragonmantank
Dayton PHP, April 2017
Sunshine PHP 2017 1
![Page 2: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/2.jpg)
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.”
Sunshine PHP 2017 2
https://www.docker.com/whatisdocker/
![Page 3: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/3.jpg)
Containers
Sunshine PHP 2017 3
![Page 4: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/4.jpg)
Normal Bare-Metal Server
Sunshine PHP 2017 4
CPU RAM HD Network
Operating System
nginx PHP DB
![Page 5: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/5.jpg)
Virtual Machines
Sunshine PHP 2017 5
CPU RAM HD Network
Operating System
nginx PHP DB
Operating System
nginx PHP DB
Operating System
Hypervisor
![Page 6: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/6.jpg)
Containers
Sunshine PHP 2017 6
CPU RAM HD Network
Operating System
nginxnginx PHP DB PHP DB
![Page 7: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/7.jpg)
Containers Are Not New
• LXC (Linux Containers)• OpenVZ• Systemd-nspawn• Qemu/kvm• BSD Jails• Solaris Zones• chroot
Sunshine PHP 2017 7
![Page 8: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/8.jpg)
Docker is an Ecosystem
Sunshine PHP 2017 8
Docker Engine
![Page 9: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/9.jpg)
Docker is an Ecosystem
Sunshine PHP 2017 9
Docker ComposeDocker Machine Docker Swarm
![Page 10: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/10.jpg)
How does it work?
Sunshine PHP 2017 10
Uses a variety of existingContainer technologies
Server ContainersHyper-V Containers xhyve Virtualization
![Page 11: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/11.jpg)
Sorry OSX < 10.10 and Windows < 10 Users
Docker Toolbox
Sunshine PHP 2017 11
![Page 12: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/12.jpg)
Using Docker – The Basics
Sunshine PHP 2017 12
![Page 13: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/13.jpg)
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
Sunshine PHP 2017 13
![Page 14: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/14.jpg)
Running a simple shell
Sunshine PHP 2017 14
![Page 15: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/15.jpg)
Running a simple shell
Sunshine PHP 2017 15
![Page 16: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/16.jpg)
Running a simple shell
Sunshine PHP 2017 16
![Page 17: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/17.jpg)
What’s Going On?
Sunshine PHP 2017 17
Ubuntu Kernel
/+ bin/+ etc/+ dev/+ home/+ usr/+ var/+ lib/+ …
/+ bin/+ etc/+ dev/+ home/+ usr/+ var/+ lib/+ …
php
nginx
bash
![Page 18: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/18.jpg)
Running Multiple Copies of Software
Sunshine PHP 2017 18
![Page 19: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/19.jpg)
Running Two Webservers
Sunshine PHP 2017 19
![Page 20: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/20.jpg)
Running Two Webservers
Sunshine PHP 2017 20
![Page 21: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/21.jpg)
Running Two Webservers
Sunshine PHP 2017 21
![Page 22: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/22.jpg)
Running Two Webservers
Sunshine PHP 2017 22
![Page 23: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/23.jpg)
Running Two Webservers
Sunshine PHP 2017 23
![Page 24: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/24.jpg)
Running Two Webservers
Sunshine PHP 2017 24
![Page 25: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/25.jpg)
Running Two Webservers
Sunshine PHP 2017 25
![Page 26: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/26.jpg)
Running Two Webservers
Sunshine PHP 2017 26
![Page 27: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/27.jpg)
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
Sunshine PHP 2017 27
![Page 28: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/28.jpg)
As a Dev Environment
Sunshine PHP 2017 28
![Page 29: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/29.jpg)
Volumes
Sunshine PHP 2017 29
![Page 30: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/30.jpg)
Mounting from the host machine
Sunshine PHP 2017 30
![Page 31: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/31.jpg)
Mounting from the host machine
Sunshine PHP 2017 31
![Page 32: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/32.jpg)
Mounting from the host machine
Sunshine PHP 2017 32
![Page 33: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/33.jpg)
Mounting from the host machine
Sunshine PHP 2017 33
![Page 34: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/34.jpg)
Mounting from the host machine
Sunshine PHP 2017 34
![Page 35: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/35.jpg)
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
Sunshine PHP 2017 35
![Page 36: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/36.jpg)
Simulating Networks
Sunshine PHP 2017 36
![Page 37: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/37.jpg)
Networking
• Docker can create multiple network “pools”• Each container gets an IP address• Containers can be attached to multiple networks• Docker network allow service discovery inside networks
Sunshine PHP 2017 37
![Page 38: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/38.jpg)
Legacy - Docker Links
• Legacy Links work with `--link`• Only works on the legacy “bridge” network• Doesn’t support service discovery
• Not worth it to use anymore
Sunshine PHP 2017 38
![Page 39: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/39.jpg)
Docker Networks
• Discreet IP pool for containers• Containers can be added and removed to the network at whim• Service discovery though ‘--network-alias’• Can be set up to work across hosts
Sunshine PHP 2017 39
![Page 40: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/40.jpg)
Create a network
Sunshine PHP 2017 40
![Page 41: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/41.jpg)
Attach to a network
Sunshine PHP 2017 41
![Page 42: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/42.jpg)
Ping the web container
Sunshine PHP 2017 42
![Page 43: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/43.jpg)
Add another web and kill web1
Sunshine PHP 2017 43
![Page 44: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/44.jpg)
Building Custom Environments
Sunshine PHP 2017 44
![Page 45: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/45.jpg)
Custom Images
• PHP images are pretty bare• Lots of times need to install extensions
Sunshine PHP 2017 45
![Page 46: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/46.jpg)
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
Sunshine PHP 2017 46
![Page 47: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/47.jpg)
docker/Dockerfile
FROM php:apache
RUN a2enmod rewrite
Sunshine PHP 2017 47
![Page 48: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/48.jpg)
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
Sunshine PHP 2017 48
![Page 49: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/49.jpg)
Build it
docker build -t d4dapp docker/
Sunshine PHP 2017 49
![Page 50: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/50.jpg)
Sunshine PHP 2017 50
![Page 51: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/51.jpg)
Use the new image
docker run -d --name d4dapp \
-v C:\drago\Projects\dockerfordevs-app:/var/www/ \
-p 8080:80
d4dapp
Sunshine PHP 2017 51
![Page 52: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/52.jpg)
Use the new image
Sunshine PHP 2017 52
![Page 53: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/53.jpg)
Containerizing Build Components
Sunshine PHP 2017 53
![Page 54: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/54.jpg)
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 \
install
Sunshine PHP 2017 54
![Page 55: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/55.jpg)
Run Multi-Tier Applications
Sunshine PHP 2017 55
![Page 56: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/56.jpg)
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
Sunshine PHP 2017 56
![Page 57: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/57.jpg)
Sample docker-compose.ymlversion: '2'
volumes: mysqldata: driver: local
services: d4dapp: build: ./docker/ volumes: - ./:/var/www/ ports: - 8080:80
mysqlserver: image: mysql environment: MYSQL_DATABASE: dockerfordevs MYSQL_ROOT_PASSWORD: 's3curep@assword' volumes: - mysqldata:/var/lib/mysql
Sunshine PHP 2017 57
![Page 58: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/58.jpg)
No longer use docker run
$ docker rm –f d4dapp
$ docker-compose up -d
Sunshine PHP 2017 58
![Page 59: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/59.jpg)
Now we have 2 containers
Sunshine PHP 2017 59
![Page 60: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/60.jpg)
Other Tools
Sunshine PHP 2017 60
![Page 61: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/61.jpg)
Docker Ecosystem
• Docker Machine• Docker Swarm
Sunshine PHP 2017 61
![Page 62: Why Docker? Dayton PHP, April 2017](https://reader031.fdocuments.in/reader031/viewer/2022022415/5a6477727f8b9afc4d8b4799/html5/thumbnails/62.jpg)
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
Sunshine PHP 2017 62