Docker: An easy introduction to containerization

Baptiste MOINE <contact@bmoine.fr>

@Creased_

Who am I?

~$> whois bmoine.fr
%%
%% Please contact Baptiste MOINE <contact@bmoine.fr> to obtain more information about me.
%%

contact:     Baptiste MOINE
country:     FR
e-mail:      contact@bmoine.fr
website:     https://www.bmoine.fr
website:     https://git.bmoine.fr
website:     https://twitter.com/Creased_
motto:       Learning is Endless
status:      ACTIVE
last-update: 1s ago

trouble:     Information: https://www.bmoine.fr
trouble:     Questions:  mailto:contact@bmoine.fr
trouble:     Spam: rm -rf / 2>/dev/null

Docker: An easy introduction to containerization

2

Plan

  1. What's Docker?

    4

  2. How it works?

    5

  3. How to use it?

  4. 7

  5. Immutable service?

  6. 9

  7. Go further

  8. 11

Docker: An easy introduction to containerization

3

What's Docker?

  • « Build, Ship and Run Any App, Anywhere »
  • Lightweight container management service set
  • Cargo container for Immutable Service Delivery
  • Environment as a code (git primitives : tag, diff, pull, push, commit)
  • Moby Project: container-based toolkits

Docker: An easy introduction to containerization

4

How it works?

Docker: An easy introduction to containerization

5

Linux Containers vs. Docker

CC-BY-NC-SA Baptiste MOINE – bmoine.fr

any app, anywhere!

How it works?

  • runC (OCI-compliant runtime) + containerd (OCI interface)
  • COW FS (e.g., AUFS) : store only the modified data
  • Namespaces (e.g., socket, PID, UID)
  • CGroups (performance management)
  • Capabilities (e.g., CAP_NET_ADMIN, CAP_SYS_ADMIN)
  • Security management (e.g., AppArmor, SELinux, Seccomp)

Docker: An easy introduction to containerization

6

How to use it?

  • Docker-CLI (interact with container manually):
$> docker run --rm --detach --interactive --tty \
              --hostname demo-nginx --name demo-nginx \
              --network bridge --publish 80:80/tcp \
              --health-cmd "wget -s -q http://127.0.0.1/ && echo \"Up\" || echo \"Down\"" \
              --health-interval 5s --health-timeout 3s \
          library/nginx:stable-alpine

aa64bb4ab8830d2b5f5c52b5f9490c6d576b4c21bc50a1174b56156181eeb8e3

$> docker logs demo-nginx

127.0.0.1 - - [20/Feb/2018:05:20:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Wget" "-"

$> docker ps --filter "name=demo-nginx" --format "{{ .Status }}"

Up 5 seconds (healthy)

$> docker stop demo-nginx

unsustainable, tedious

Docker: An easy introduction to containerization

7

How to use it?

  • Docker-Compose (describe and deploy a service bundle using a recipe file):
$> docker-compose up -d

Creating network "dockerdemo_front" with driver "bridge"
Creating demo-nginx ... done

$> docker-compose logs

Attaching to demo-nginx
demo-nginx | 127.0.0.1 - - [20/Feb/2018:05:20:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Wget" "-"

$> docker-compose ps

   Name            Command          State         Ports       
--------------------------------------------------------------
demo-nginx   nginx -g daemon off;   Up      0.0.0.0:80->80/tcp

accessible, efficient

Docker: An easy introduction to containerization

8

Immutable service?

  • Dockerfile (describe an image content):
#
# Nginx Dockerfile
#
# Written by:
#   Baptiste MOINE <contact@bmoine.fr>
#

# Pull base image.
FROM library/nginx:stable-alpine

# Describe image.
MAINTAINER Baptiste MOINE <contact@bmoine.fr>

# Copy startup script.
COPY ./start.sh /start.sh
RUN chmod +x /start.sh

# Define command and entrypoint.
CMD ["/start.sh"]

Docker: An easy introduction to containerization

9

user-friendly, maintainable

Immutable service?

  • Build and deploy image (git primitives):
$> docker-compose pull
$> docker-compose build

Successfully built a4aea8a6250f
Successfully tagged creased/nginx:stable-alpine

$> docker-compose push
$> docker-compose up -d

Creating network "dockerdemo_front" with driver "bridge"
Creating demo-nginx ... done

$> docker-compose logs

Attaching to demo-nginx
demo-nginx | 127.0.0.1 - - [20/Feb/2018:05:20:00 +0000] "GET / HTTP/1.1" 200 612 "-" "Wget" "-"

$> docker-compose ps

   Name            Command          State         Ports       
--------------------------------------------------------------
demo-nginx   nginx -g daemon off;   Up      0.0.0.0:80->80/tcp

Docker: An easy introduction to containerization

10

fast, memory-friendly

Go further

CI/CD pipeline based on GitLab

CC-BY-NC-SA Baptiste MOINE – bmoine.fr

  • Manual: 1, 12-13 (facultative)
  • Automatic: 2-12

Docker: An easy introduction to containerization

11

Go further

Docker: An easy introduction to containerization

12

Introduction to containerization with Docker

By Baptiste MOINE

Introduction to containerization with Docker

Easy introduction to containerization with Docker talk

  • 1,367