Thanks to tools like vagrant, puppet/chef, and Platform as a Service services like Heroku, developers are extremely used to being able to spin up a development environment that is the same every time. What if we could go a step further and make sure our development environment is not only using the same software, but 100% configured and set up like production. Docker will let us do that, and so much more. We’ll look at what Docker is, why you should look into using it, and all of the features that developers can take advantage of.
2. 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.”
JetBrains, June 2016 2
https://www.docker.com/whatisdocker/
7. Containers Are Not New
• LXC (Linux Containers)
• OpenVZ
• Systemd-nspawn
• Qemu/kvm
• BSD Jails
• Solaris Zones
• chroot
JetBrains, June 2016 7
8. Docker is an Ecosystem
JetBrains, June 2016 8
Docker Engine
9. Docker is an Ecosystem
JetBrains, June 2016 9
Docker ComposeDocker Machine Docker Swarm
10. How does it work?
JetBrains, June 2016 10
Uses a variety of existing
Container technologies
Server Containers
Hyper-V Containers xhyve Virtualization
11. Sorry OSX < 10.10 and Windows < 10 Users
Docker Toolbox
JetBrains, June 2016 11
13. 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
JetBrains, June 2016 13
25. 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
JetBrains, June 2016 25
27. Modifying a running container
• `docker exec` can run a command inside of an existing container
• Use Volumes to share data
JetBrains, June 2016 27
28. Persistent Data with Volumes
• You can designate a volume with -v
• Volumes can be shared amongst containers
• Volumes can mount data from the host system
JetBrains, June 2016 28
34. 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
JetBrains, June 2016 34
35. Container Data Volumes
• Uses a small container that does nothing but store data
• Have our app containers use the data volume to store data
• Use ‘editor containers’ to go in and modify data when needed
JetBrains, June 2016 35
44. Why go through the hassle?
• Data volumes are portable
• Data volumes are safer
• Separates the app containers from data
• Production can use a data volume, dev can use a host volume
• Our app containers stay small
JetBrains, June 2016 44
46. Docker Links
• Allows containers to ‘see’ each other over the network
• Each container thinks the other one is just another machine
• Containers all have an internal network address, so we don’t need to
expose everything through the host
JetBrains, June 2016 46
54. More Notes!
• We can now rebuild sections of the app as needed
• We can restart nginx without impacting PHP
• We can extend much easier
• Docker 1.12 has added a whole bunch of new stuff
JetBrains, June 2016 54
56. 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
JetBrains, June 2016 56
58. 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
JetBrains, June 2016 58
60. Inspect a container
docker inspect [options] CONTAINER_NAME
• Returns a JSON string with data about the container
• Can also query
• docker inspect -f “{{ .NetworkSettings.IPAddress }}” web_server
• Really handy for scripting out things like reverse proxies
JetBrains, June 2016 60
61. Work with images
• docker pull IMAGE – Pulls down an image before using
• docker images – Lists all the images that are downloaded
• docker rmi IMAGE – Deletes an image if it’s not being used
JetBrains, June 2016 61
63. What is Docker Machine?
• A provisioning tool that is used to set up a box with Docker
• Used in Docker Toolbox to create the VM
• Supports:
• EC2
• Azure
• Digital Ocean
• Hyper-V
• OpenStack
• Virtualbox
• VMWare
JetBrains, June 2016 63
64. Why use it?
• Makes it very easy to spin up new boxes
• Docker Machine handles all of the dirty stuff for you
• Docker Toolbox users are already using it
• Integrates with Docker Swarm
• It is not necessarily portable
JetBrains, June 2016 64
66. What is Docker Swarm?
• Cluster management tool developed by Docker
• Looks like a machine running docker, but is actually many machines
• This has changed and grown a lot in Docker 1.12
JetBrains, June 2016 66
68. 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
JetBrains, June 2016 68
81. Notes
• Does support docker-compose.yml files and setups as
deployments
• Doesn’t support custom Docker Compose settings files
JetBrains, June 2016 81
82. Thank You!
• https://github.com/dragonmantank
• Author of “Docker for Developers”
• https://leanpub.com/dockerfordevs
• http://ctankersley.com
• chris@ctankersley.com
• @dragonmantank
JetBrains, June 2016 82