What is Docker?
Docker is an
- easy to use
- and cross-platform
wrapper for the Linux Containers (LXC).
What are Linux Containers?
LXC (LinuX Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host.
Why Containers?
Because you can put any type of application in them and every Linux operating system nows how to deal with them:
Why not use normal Virtualization?
No Hypervisors. No extra OS. No overhead.
What does Docker do?
Lightweight infrastructure virtualization and app isolation.
Docker is a tool that can package an application and its dependencies in a virtual container that can run on any Linux server.
- Standardization: A common interface for Operating Systems
- Packaging and distribution
- Sandboxing
see: Understanding Docker
Why use Docker?
- ISOLATION!
- Repeatable Setups -> Configuration Management on PROD does not work (see: NDC 2014 - Docker is the future of shipping our code)
- Versioned application stacks -> images for each release and customer
- Replication of PROD environment setups on DEV and INT
- Because we have hige dedicated servers, no virtualization and no cloud.
- Full-Virtualization is too much overhead
- Portability (OS, Hoster, Cloud)
Vagrant & Docker
Why Vagrant?
Docker uses Linux containers (LXC) and Linux Containers are only available for Linux system with a kernel greater than 2.6.24.
On platforms that don’t support Linux Containers natively such as Mac OS X and Windows, Vagrant automatically brings up and shares a proxy virtual machine to run Docker.
Vagrant and Docker work well together
We’ll be interviewing as a team … and we’re here to fuck shit up!
Vagrant* natively supports Docker
Links:
Components and Terms
- Dockerfile := metadata file for creating docker containers from images
- Docker Image := a read-only OS template
- UnionFS := layer filesystem
- Docker Registry := public or private stores from which you upload or download images
- Docker Container := is created from a Docker image and holds everything that is needed for an application to run
Dockerfile
Dockerfile’s are used for automating the setup of Docker images.
FROM ubuntu
MAINTAINER Firstname Lastname <[email protected]>
RUN apt-get update
RUN apt-get install nginx
EXPOSE 80
see: Dockerfile Reference
Docker Image
Docker images are read-only templates from which Docker containers are launched. Each image consists of a series of layers. Docker makes use of union file systems to combine these layers into a single image.
UnionFS
This allows Docker Images to stay small.
Union file systems allow files and directories of separate file systems, known as branches, to be transparently overlaid, forming a single coherent file system.
see: Wikipedia: UnionFS
Docker Registry
The public Docker registry is called Docker Hub.
Docker Container
- A Docker container holds everything that is needed for an application to run (like a directory).
- Each container is created from a Docker image.
- Docker containers can be run, started, stopped, moved, and deleted.
- Each container is an isolated and secure application platform.
Installation
Windows
docs.docker.com/installation/windows
Ubuntu
docs.docker.com/installation/ubuntulinux
sudo apt-get update
sudo apt-get install docker.io
sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
CentOs
docs.docker.com/introduction/understanding-docker
sudo yum install docker-io
sudo service docker start
sudo chkconfig docker on
Test the installation:
sudo docker pull centos:latest
sudo docker images centos
sudo docker run -i -t centos /bin/bash
Hands on Docker
Using boot2docker on Windows
github.com/boot2docker/boot2docker
boot2docker help
boot2docker init
boot2docker up
boot2docker ssh
1. Listing the available commands
To get help information about the available commands call docker without arguments:
docker
2. Get help about a Docker command
To get help information about a docker command use this syntax:
docker help <command-name>
Example: Get help about the “pull” command
sudo docker help pull
3. Listing Available Images
Images can be listed with the images
command:
sudo docker images
4. Download a pre-built Docker image
Download (the layers of) the ubuntu Docker image from the Docker Registry:
sudo docker pull ubuntu
5. Running a shell in the image
Use the new Docker image to run an interactive (bash) shell:
sudo docker run -i -t ubuntu /bin/bash
Execute some command in the shell:
hostname
ifconfig
top
exit
6. Running Processes as deamons
Docker instances can be addresses by their SHA-1 hash (or a protion of it). You can use the hash to get logs from a container, to get a container’s status with ps or kill a container:
ContainerId=$(sudo docker run -d ubuntu /bin/sh -c 'while true; do echo $(date); sleep 1; done')
sudo docker logs $ContainerId
sudo docker kill $ContainerId
7. Listing Available Containers
You can query running containers with ps
and all available containers with ps -a
:
sudo docker ps
sudo docker ps -a
8. Interacting with Containers
Things you can do with an exiting/running container:
- inspect (get container details)
- attach (log in)
- logs (show the container logs)
- commit (create a new image from a container)
- start
- restart
- stop (shutdown gracefully)
- kill (shutdown immediately)
- rm (remove)
Syntax:
sudo docker <action> <ContainerId>
9. Connecting Ports
You can specify a port for a container using the -p
parameter for the run
command:
sudo docker run -d -p <Container-Port> ubuntu /bin/nc -l <Container-Port>
Find out to which local port the container is connected:
sudo docker port <ContainerId> <Container-Port>
Testing the connection by sending data to the local port:
echo "A test message" | nc 127.0.0.1 <Local-Port>
10. Mounting Directories
sudo docker run -i -t -v <source-path>:<target-path> ubuntu /bin/bash
11. Linking containers
see: docker: Linking Containers Together
Real World Examples
Run this presentation as a Docker Image
sudo docker run -d -p 80:80 andreaskoch/docker-presentation /usr/bin/start-presentation
Goto: http://localhost
Magento Development Setup
Start the following “utility” services:
- Redis
- Solr
Configure a database server:
- MySql
Pass the Redis and Solr connections to the web-server image:
- Nginx
- Configuration via Vagrantfile
- Port Mapping
- Bootstrap project
- Upload database
- Port Mapping
- Configuration via Vagrantfile
Underlying Technology
Examining the Docker AUFS Filesystem
Dockers stores the image files in the folder /var/lib/docker/aufs
:
My Goals with Docker
- Short Term
- Setup Docker containers that can be used for DEV and INT environments
- Nginx
- MySql
- Redis
- SolR
- Memcached
- Nginx
- Isolate Magento-instances in Docker containers (Nginx + PHP-FPM + Magento)
- Setup Docker containers that can be used for DEV and INT environments
- Mid Term
- Versioning of Magento projects in Docker instances
- Private Docker Registry
- Versioning for the different projects
- Private Docker Registry
- Use Magento-Containers on INT to isolate the different customers from each other
- Setup a plan for running Dockers instances on PROD
- Use Magento-Containers on PROD to isolate the different customers from each other
- Versioning of Magento projects in Docker instances
- Long Term
- Evaluate the use of Docker-containers for MySql, Redis and SolR on PROD
- Use Magento-Containers on different hosting platforms (Azure, dotCloud, AWS, …)
- Evaluate the use of Docker-containers for MySql, Redis and SolR on PROD
Learning Docker
Video: Introduction to Docker
The Docker User Guide
Video: Docker 101
Docker Online Tutorial
Video: Managing containers with Docker
Pluralsight: Docker Fundamentals Course
pluralsight: Docker Fundamentals
Video: Docker is the future of shipping our code
Who supports Docker?
- dotCloud
- tutum
- ORCHARD
- Google
- Amazon Web Services
- Microsoft Azure
- Rackspace
- DigitalOcean
- IBM
Use Cases
Use cases at MailGun (Rackspace)
Use cases at Spotity
Run Docker Containers on AWS Elastic Beanstalk
The Future of Docker
Links