Getting started with Docker

Introduction to container virtualization with docker.
created by on 2014-06-28

Docker Logo


What is Docker?

Docker is an

wrapper for the Linux Containers (LXC).

Docker explained by Solomon Hykes

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.

Linux Containers Explained

Why Containers?

Because you can put any type of application in them and every Linux operating system nows how to deal with them:

Figure: Why Containers?


Why not use normal Virtualization?

No Hypervisors. No extra OS. No overhead.

Figure: Hypervisor Virtualization vs. Container Virtualualization


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.

see: Understanding Docker


Why use Docker?


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.

Why Vagrant?


Vagrant and Docker work well together

We’ll be interviewing as a team … and we’re here to fuck shit up!

Step Brothers: We are here to fuck shit up


Vagrant* natively supports Docker

Docker-Based Development Environments With Vagrant

Links:

* since version 1.6


Components and Terms


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.

Figure: Dockers' multilayer filesystem


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.

Figure: Layer Filesystem

see: Wikipedia: UnionFS


Docker Registry

The public Docker registry is called Docker Hub.

Screenshot: Docker Registry


Docker Container


Installation


Windows

docs.docker.com/installation/windows

boot2docker on 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
Screencast: boot2docker on Windows

1. Listing the available commands

To get help information about the available commands call docker without arguments:

docker

Screentshot: List the available docker commands


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

Screenshot: Get help information for a Docker Command


3. Listing Available Images

Images can be listed with the images command:

sudo docker images

Screenshot: List available images


4. Download a pre-built Docker image

Download (the layers of) the ubuntu Docker image from the Docker Registry:

sudo docker pull ubuntu

Screenshot: Downloading a pre-built docker image


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

Shell Recording: Running an interactive bash shell in a Docker image


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

Shell Recording: Long-Running processes in docker


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

Screenshot: Listing containers with ps -a


8. Interacting with Containers

Things you can do with an exiting/running container:

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

Managing Data in Containers

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
Screencast: run andreaskoch/docker-presentation

Goto: http://localhost


Magento Development Setup

Start the following “utility” services:

Configure a database server:

Pass the Redis and Solr connections to the web-server image:


Underlying Technology


Examining the Docker AUFS Filesystem

Dockers stores the image files in the folder /var/lib/docker/aufs:

Screenshot: Docker images files int AUFS folder


My Goals with Docker

  1. Short Term
    • Setup Docker containers that can be used for DEV and INT environments
      • Nginx
      • MySql
      • Redis
      • SolR
      • Memcached
    • Isolate Magento-instances in Docker containers (Nginx + PHP-FPM + Magento)
  2. Mid Term
    • Versioning of Magento projects in Docker instances
      • Private Docker Registry
      • Versioning for the different projects
    • 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
  3. 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, …)

Learning Docker


Video: Introduction to Docker

Introduction to Docker

The Docker User Guide

docs.docker.com/userguide

Screenshot: The Docker User Guide


Video: Docker 101

Docker 101 session

Docker Online Tutorial

www.docker.com/tryit

Screenshot: Docker Online Tutorial


Video: Managing containers with Docker

CCC Easterhegg 2014 - Managing containers with Docker

Pluralsight: Docker Fundamentals Course

pluralsight: Docker Fundamentals

Screenshot: Pluralsight - Docker Fundamentals Course - Table of Contents


Video: Docker is the future of shipping our code

NDC 2014 - Paul Stack - Docker is the future of shipping our code

Who supports Docker?


Use Cases


Use cases at MailGun (Rackspace)

How MailGun uses docker

Use cases at Spotity

Docker at Spotify

Run Docker Containers on AWS Elastic Beanstalk

Use AWS Elastic Beanstalk to Run a Docker Container from the Docker Registry

see: AWS Elastic Beanstalk


The Future of Docker

Links

Shortlink:
Tags:
Fork allmark on GitHub