Introductory seminar on Docker and its components (networks and Compose in particular). Focused on going through some basic concepts, mention some more advanced topics, and introduce a practical workshop held on the same evening.
2. About me
• 15 years “in the trenches cubicles”
• Developer of RTC (VoIP, IM, WebRTC) solutions
• Often dealing with DevOps topics
• Founder of RTCSoft in 2015
@giavac
https://github.com/giavac
gv@rtcsoft.net
2
5. Previously on this show 1/2
http://www.slideshare.net/GiacomoVacca/docker-and-puppet-for-continuous-integration
5
6. Previously on this show 2/2
http://www.slideshare.net/GiacomoVacca/docker-from-scratch
6
7. What is Docker, really?
• An Open-Source (Go) framework to manage “container virtualisation” (started in 2013)
• Docker isolates multiple user spaces (file systems) inside the same host
• The user space instances are called “Containers”
• They give you the illusion of being inside a VM
• Think about “execution environments” or “sandboxes”
• No need for an hypervisor (and so very quick to launch)
• Requires x64 Linux and kernel 3.8+
• Google started dev of cgroups for the Linux kernel, then together with namespaces and chroot become LXC
7
8. Main Docker components
• Engine: manages images and containers. Exposes an API
• Client: connects to the Engine (locally or remotely)
• Compose: manages multi-container architectures
• Swarm: orchestrates containers on multiple hosts
• Kitematic: GUI for Docker client
• Machine: provision and manage VMs to host containers
8
11. What Docker is not?
• A programming language
• An OS
• A Virtual Machine
• An image in the traditional hypervisor-based Virtual Machine concept
11
12. Where is Docker used?
• Uber, eBay, BBC News, shopify, ING, Swisscom, Groupon (1)
• and many others…
• Supported by Google Cloud Platform
• with the Container Engine + Kubernetes
(1) source: https://www.docker.com/customers
12
13. Who should know about Docker?
• Developers
• Including mobile developers
• Sysadmins
• “DevOps” people
• Architects/CTO/COO
13
14. Basic topics
• Images and Containers
• Image structure
• Dockerfiles
• Building an image
• Interacting with an image repo
• Running a container
14
• Architecture
• Typical Linux vs Toolbox
• Volumes
• Port mapping
15. Some advanced topics
• Inspecting/debugging containers
• inspect/attach/exec/logs/top
• Volumes, data containers
• Multicontainer architectures
• Link, network, Compose
• Docker inside Docker
• Is it worth it? Consider the “sibling” approach (“socket mounting”) instead.
• Orchestrating Docker containers via Puppet
15
18. Debugging a container
$ docker info
$ docker attach CONTAINER_NAME
$ docker exec -it CONTAINER_NAME COMMAND
e.g. ‘$ docker exec -it gvacca/nginx /bin/bash’
$ docker logs CONTAINER_NAME
Or show processes running inside a container:
$ docker top CONTAINER_NAME
18
19. Volumes
• Share a folder between host and container
• VOLUME commands inside the Dockerfile
• Dynamic volume association at run time: one or more ‘-v’ arguments
• Volumes shared by an image are available even if the container is
not running (but it needs to still exist).
19
20. Multicontainer architecture
• Define many containers (aka “services”)
• Define relationship between them (e.g. “depends on”)
• Define networking
• Start/Stop all services at the same time
20
21. Networks of Containers
• “docker network” defined since Docker 1.9
• Create a virtual network, then attach containers to it
• Containers on different networks by default don’t see each other
• Internal private addressing, managed by Docker
• Brilliant for prototyping and emulating entire architectures
21
23. Docker Compose
• docker-compose.yml, defines a set of containers (“services”). Written in python,
available with Toolbox.
• Define their runtime properties (images, volumes, ports, dependencies)
• Interact with registries (public/private)
• Network
• Containers can be located with a name, instead of IP address (e.g ‘https://
mysql_server:3306’, from 1.6.2)
• Default name is ‘APPFOLDER_default’
23
25. Docker Machine
• Provision and manage VMs
• Available with Toolbox (uses Virtualbox)
• ‘docker-machine active’
• ‘docker-machine ls’
• ‘docker-machine start default’
• eval $(docker-machine env)
25
26. Let’s play with Docker Compose
• Write your docker-compose.yml file
• ’docker-compose build [service]’
• Builds the images when needed (‘build’), or exits (‘image’)
• ’docker-compose up’
• Add ‘-d’ to run in background (daemon mode)
• ‘docker ps’ to see the launched containers
• ‘docker-compose ps’
• See the processes and other details - similar to ‘docker ps’
• ‘docker-compose down/stop/kill’
• To switch off the node
26
27. The Workshop
• Create a simple app with 2 containers
• One with stock image
• One with built image
• Run and inspect
• Check volumes
• Create the same app with Compose
• Run and inspect
• Check network and volumes
27
28. Compose scenario - steps
Browse to http://192.168.99.100:5000/
docker-compose --verbose up
Browse to http://192.168.99.100:5000/
CTRL+C
docker-compose --verbose up -d
docker ps | grep 'composetest'
docker-compose ps
docker-compose --verbose ps
docker network ls |grep 'composetest'
docker network inspect 'composetest_default'
python inspect_docker_network.py 'composetest_default'
28
29. docker ps
Giacomos-MacBook-Pro:docker-experiments gv$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
13398ae967e5 gvacca/kamailio_async:ubuntu14 "tail -f /dev/null" 3 months ago Up 3 seconds
5060/tcp dockerexperiments_kamailio_async_ubuntu_1
51c8105ef7ab gvacca/kamailio_async:centos7 "tail -f /dev/null" 3 months ago Up 3 seconds
5060/tcp dockerexperiments_kamailio_async_centos_1
4e21f9fd9694 gvacca/sipp "tail -f /dev/null" 3 months ago Up 3 seconds
dockerexperiments_sipp_1
381272e54d19 gvacca/nginx_ssl "/bin/sh -c nginx" 3 months ago Up 3 seconds
80/tcp, 443/tcp dockerexperiments_nginx_ssl_1
29