SlideShare a Scribd company logo
FROM scratch
MAINTAINER Michal Wojtowicz michal@wojtowicz.ovh
Docker from scratch
WHAT IS DOCKER?WHAT IS DOCKER?
makes easier to create, build and ship apps in
containers
single build contains only your application,
libs/dependencies
follows Open Container Initiative (part of Linux
Foundation)
WHAT IS A CONTAINER?WHAT IS A CONTAINER?
WHAT IS A CONTAINER?WHAT IS A CONTAINER?
It looks like VM:
own process space
own network
can run things as root
can install packages
can play with system services
WHAT IS A CONTAINER?WHAT IS A CONTAINER?
But it's not a VM:
share host's kernel
can't boot different OS
boot much faster
HOW CONTAINER DIFFERS FROM VM?HOW CONTAINER DIFFERS FROM VM?
HOW CONTAINER DIFFERS FROM VM?HOW CONTAINER DIFFERS FROM VM?
VIRTUALIZATION ON LINUXVIRTUALIZATION ON LINUX
Containers share same Linux Kernel as host
machine
They always share Linux kernel
VIRTUALIZATION ON OSX AND WINDOWSVIRTUALIZATION ON OSX AND WINDOWS
Requires additional Virtual Machine with Linux
Kernel
Hyper-V on Windows 10
HyperKit on macOS since Yosemite
Docker-machine (based on Virtualbox) on earlier
versions
KERNEL NAMESPACES - WHAT'S THEKERNEL NAMESPACES - WHAT'S THE
POINT?POINT?
Each process is associated with a namespace and can
only see or use the resources associated with that
namespace, and descendant namespaces where
applicable.
PID NAMESPACEPID NAMESPACE
processes can see each other in bounds of same PID
namespace
when PID 1 is killed, whole namespace is killed
either
NET NAMESPACENET NAMESPACE
Allows to own private network stack including:
interfaces
routing tables
firewall rules
sockets
MNT NAMESPACEMNT NAMESPACE
isolates mount points for a processes
allows different views of the host's files
mount points can be shared
UTS NAMESPACEUTS NAMESPACE
isolates the hostname and the NIS domain name
IPC NAMESPACE (INTERPROCESSIPC NAMESPACE (INTERPROCESS
COMMUNICATION)COMMUNICATION)
semaphores
POSIX message queues
shared memory
USER NAMESPACEUSER NAMESPACE
table of user IDs
maps container's user to host user
used for priviledge isolation
WHAT IS NOT NAMESPACED?WHAT IS NOT NAMESPACED?
time - try to change it inside the container
/ # whoami
root
/ # uname -a
Linux 51a456ca0479 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4
/ # date +%T -s "10:13:13"
date: can't set date: Operation not permitted
kernel keyring - syscalls are also blocked
things under /sys/
ONE SERVICE - ONE CONTAINERONE SERVICE - ONE CONTAINER
PHILOSOPHYPHILOSOPHY
easier to scale
easier to maintain
doesn't face first process assassination issue
more effort needed to configure than VM-like
approach
DOCKER IMAGEDOCKER IMAGE
WHAT IS AN IMAGE?WHAT IS AN IMAGE?
overlays kernel
can contain libraries/binaries
can define exposed ports, workdir
runs default process in container
WHAT'S INSIDE THE IMAGE?WHAT'S INSIDE THE IMAGE?
Linux distro dependencies like in Ubuntu image
Prebuilt dependencies for app useful in containers
Everything is packed up as layers
Images are read-only
HOW TO BUILD OWN IMAGE?HOW TO BUILD OWN IMAGE?
FOLLOW DOCKERFILE SYNTAXFOLLOW DOCKERFILE SYNTAX
FROM <image>[:<tag>] # base image
RUN <command> # runs command only once during build
CMD command param1 param2 # runs on container boot
EXPOSE <port> [<port>/<protocol>...]
ENV <key> <value> # only inside a container
ADD [--chown=<user>:<group>] <src>... <dest>
COPY <src>... <dest>
ENTRYPOINT command param1 param2 # container will run as an ex
VOLUME ["/data"]
USER <user>[:<group>] # who runs executables
WORKDIR /path # where run executables
HEALTHCHECK [OPTIONS] CMD command
$ docker build .
Sending build context to Docker daemon 15.36 kB
Step 1/4 : FROM alpine:3.2
---> 31f630c65071
Step 2/4 : MAINTAINER forest.gump@example.com
---> Using cache
---> 2a1c91448f5f
Step 3/4 : RUN apk update && apk add apache2 && rm -r /var/cac
---> Using cache
---> 21ed6e7fbb73
Step 4/4 : CMD apache2
---> Using cache
---> 7ea8aef582cc
Successfully built 7ea8aef582cc
RUNNING CONTAINERRUNNING CONTAINER
$ docker run -it ubuntu:14.04 /bin/bash
$ docker run -it tomcat -d -p 8080:80
DOCKER-COMPOSE - TO THE RESCUEDOCKER-COMPOSE - TO THE RESCUE
version: '3'
services:
web:
image: apache
links:
- database
ports:
- '8080:80'
volumes:
- ./project:/var/www:rw
database:
image: mysql
$ docker-compose up
CI/CDCI/CD
BITBUCKET PIPELINESBITBUCKET PIPELINES
similar syntax to docker-compose.yml
limit of only one container with mounted codebase
codebase can be mounted into different containers
with steps
services are the only way of having multiple
containers
services are reachable through network only
image: alpine:latest
pipelines:
default:
- step:
image: node:8.9.4
caches:
- node_modules
script:
- npm run build
branches:
master:
- step:
script:
- ./generateReleaseNotes.sh
GITLAB PIPELINESGITLAB PIPELINES
can organise chain of processes which leads to release
GITLAB PIPELINESGITLAB PIPELINES
limit of only one container with mounted codebase
codebase can be mounted into different containers
with jobs
services are the only way of having multiple
containers
services are reachable through network only
image: php:latest
services:
- mysql:5.7
variables:
MYSQL_DATABASE: fancyDB
MYSQL_ROOT_PASSWORD: secret
DB_HOST: mysql
DB_USERNAME: root
stages:
- test
- deploy
SECURITY - GET RID OF ROOTSECURITY - GET RID OF ROOT
PRIVILEGESPRIVILEGES
follow the principle of least privilege
Docker requires root privileges to run, containers
themselves do not
process running in a container is no different from
other process
many images just run as root and leave it up to you
$ docker run -v /root:/tmp/rootdir alpine:latest ls -la /tmp/r
drwxr-xr-x+ 126 root root 4032 Jun 21 13:43 .
drwxr-xr-x 7 root root 224 Jun 15 12:31 ..
-rw-r--r-- 1 root root 266 Nov 26 2017 secretFile
FROM anyimage:latest
RUN groupadd -g 999 appuser && 
useradd -r -u 999 -g appuser appuser
USER appuser
Docker from scratch
ELASTIC CONTAINERELASTIC CONTAINER
SERVICE (ECS)SERVICE (ECS)
user manages clusters of containers
cluster defines type of underlying EC2 instances
one underlying instance can run many containers
it's still up to user to administrate instances
FARGATEFARGATE
user doesn't have to manage cluster and instances
user precises only CPU/memory requirements
containers are created on AWS managed instances
Kubernetes support coming in 2018
NEXT STEP - ORCHESTRASTIONNEXT STEP - ORCHESTRASTION
Docker Swarm
Kubernetes
AWS/Azure/Google solutions
QUESTIONS?QUESTIONS?
THANK YOU FORTHANK YOU FOR
YOUR TIMEYOUR TIME
Slides are available on
https://michailw.github.io/talks/docker/

More Related Content

PPTX
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
PPTX
Azure container service docker-ha noi com
PDF
Introduction to docker
PPTX
Docker Presentation
PPT
Docker introduction
PPTX
Docker introduction
PDF
Docker with openstack
PPTX
Docker - 15 great Tutorials
Docker-Hanoi @DKT , Presentation about Docker Ecosystem
Azure container service docker-ha noi com
Introduction to docker
Docker Presentation
Docker introduction
Docker introduction
Docker with openstack
Docker - 15 great Tutorials

What's hot (20)

PDF
Docker Introduction
ODP
Ruby and Docker on Rails
PDF
Docker introduction
PPTX
Docker - Demo on PHP Application deployment
PDF
Agile Brown Bag - Vagrant & Docker: Introduction
PPTX
Architecting .NET Applications for Docker and Container Based Deployments
PDF
PPTX
The challenge of application distribution - Introduction to Docker (2014 dec ...
PDF
Advanced Docker Developer Workflows on MacOS X and Windows
PPTX
PHP development with Docker
PPTX
Intro- Docker Native for OSX and Windows
PDF
Docker All The Things - ASP.NET 4.x and Windows Server Containers
PPTX
Docker Global Hack Day #3
PDF
Docker - introduction
PDF
Docker workshop
PPTX
Start your adventure with docker
PPTX
What is Docker
PDF
An Introduction to Vagrant and Docker
PDF
Building Reusable Development Environments with Docker
PDF
Dockerizing your applications - Docker workshop @Twitter
Docker Introduction
Ruby and Docker on Rails
Docker introduction
Docker - Demo on PHP Application deployment
Agile Brown Bag - Vagrant & Docker: Introduction
Architecting .NET Applications for Docker and Container Based Deployments
The challenge of application distribution - Introduction to Docker (2014 dec ...
Advanced Docker Developer Workflows on MacOS X and Windows
PHP development with Docker
Intro- Docker Native for OSX and Windows
Docker All The Things - ASP.NET 4.x and Windows Server Containers
Docker Global Hack Day #3
Docker - introduction
Docker workshop
Start your adventure with docker
What is Docker
An Introduction to Vagrant and Docker
Building Reusable Development Environments with Docker
Dockerizing your applications - Docker workshop @Twitter
Ad

Similar to Docker from scratch (20)

PPTX
Docker Container Security
PDF
Docker
PDF
Docker presentation | Paris Docker Meetup
PDF
Victor Vieux at Docker Paris Meetup #1
PDF
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
PDF
Docker 0.11 at MaxCDN meetup in Los Angeles
PDF
Introduction to Docker and Linux Containers @ Cloud Computing Rhein Main
PDF
Docker Introduction + what is new in 0.9
PDF
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
PDF
Introduction to Docker - Learning containerization XP conference 2016
PDF
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
PDF
Work shop - an introduction to the docker ecosystem
PDF
Introduction to Docker
PPTX
Dockerizing a Symfony2 application
PDF
Introduction to Docker
PPTX
Intro Docker october 2013
PPTX
Novices guide to docker
PDF
Introduction to Docker
PPTX
Primi passi con Docker - ItalianCoders - 12-01-2021
PDF
Docker_AGH_v0.1.3
Docker Container Security
Docker
Docker presentation | Paris Docker Meetup
Victor Vieux at Docker Paris Meetup #1
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Docker 0.11 at MaxCDN meetup in Los Angeles
Introduction to Docker and Linux Containers @ Cloud Computing Rhein Main
Docker Introduction + what is new in 0.9
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Introduction to Docker - Learning containerization XP conference 2016
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Work shop - an introduction to the docker ecosystem
Introduction to Docker
Dockerizing a Symfony2 application
Introduction to Docker
Intro Docker october 2013
Novices guide to docker
Introduction to Docker
Primi passi con Docker - ItalianCoders - 12-01-2021
Docker_AGH_v0.1.3
Ad

Recently uploaded (20)

PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
DOCX
573137875-Attendance-Management-System-original
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPT
Mechanical Engineering MATERIALS Selection
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Well-logging-methods_new................
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
PPT on Performance Review to get promotions
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
573137875-Attendance-Management-System-original
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Internet of Things (IOT) - A guide to understanding
Mechanical Engineering MATERIALS Selection
Arduino robotics embedded978-1-4302-3184-4.pdf
Well-logging-methods_new................
Embodied AI: Ushering in the Next Era of Intelligent Systems
Model Code of Practice - Construction Work - 21102022 .pdf
PPT on Performance Review to get promotions
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx

Docker from scratch

  • 1. FROM scratch MAINTAINER Michal Wojtowicz michal@wojtowicz.ovh
  • 3. WHAT IS DOCKER?WHAT IS DOCKER? makes easier to create, build and ship apps in containers single build contains only your application, libs/dependencies follows Open Container Initiative (part of Linux Foundation)
  • 4. WHAT IS A CONTAINER?WHAT IS A CONTAINER?
  • 5. WHAT IS A CONTAINER?WHAT IS A CONTAINER? It looks like VM: own process space own network can run things as root can install packages can play with system services
  • 6. WHAT IS A CONTAINER?WHAT IS A CONTAINER? But it's not a VM: share host's kernel can't boot different OS boot much faster
  • 7. HOW CONTAINER DIFFERS FROM VM?HOW CONTAINER DIFFERS FROM VM?
  • 8. HOW CONTAINER DIFFERS FROM VM?HOW CONTAINER DIFFERS FROM VM?
  • 9. VIRTUALIZATION ON LINUXVIRTUALIZATION ON LINUX Containers share same Linux Kernel as host machine They always share Linux kernel
  • 10. VIRTUALIZATION ON OSX AND WINDOWSVIRTUALIZATION ON OSX AND WINDOWS Requires additional Virtual Machine with Linux Kernel Hyper-V on Windows 10 HyperKit on macOS since Yosemite Docker-machine (based on Virtualbox) on earlier versions
  • 11. KERNEL NAMESPACES - WHAT'S THEKERNEL NAMESPACES - WHAT'S THE POINT?POINT? Each process is associated with a namespace and can only see or use the resources associated with that namespace, and descendant namespaces where applicable.
  • 12. PID NAMESPACEPID NAMESPACE processes can see each other in bounds of same PID namespace when PID 1 is killed, whole namespace is killed either
  • 13. NET NAMESPACENET NAMESPACE Allows to own private network stack including: interfaces routing tables firewall rules sockets
  • 14. MNT NAMESPACEMNT NAMESPACE isolates mount points for a processes allows different views of the host's files mount points can be shared
  • 15. UTS NAMESPACEUTS NAMESPACE isolates the hostname and the NIS domain name
  • 16. IPC NAMESPACE (INTERPROCESSIPC NAMESPACE (INTERPROCESS COMMUNICATION)COMMUNICATION) semaphores POSIX message queues shared memory
  • 17. USER NAMESPACEUSER NAMESPACE table of user IDs maps container's user to host user used for priviledge isolation
  • 18. WHAT IS NOT NAMESPACED?WHAT IS NOT NAMESPACED? time - try to change it inside the container / # whoami root / # uname -a Linux 51a456ca0479 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Jan 4 / # date +%T -s "10:13:13" date: can't set date: Operation not permitted kernel keyring - syscalls are also blocked things under /sys/
  • 19. ONE SERVICE - ONE CONTAINERONE SERVICE - ONE CONTAINER PHILOSOPHYPHILOSOPHY easier to scale easier to maintain doesn't face first process assassination issue more effort needed to configure than VM-like approach
  • 21. WHAT IS AN IMAGE?WHAT IS AN IMAGE? overlays kernel can contain libraries/binaries can define exposed ports, workdir runs default process in container
  • 22. WHAT'S INSIDE THE IMAGE?WHAT'S INSIDE THE IMAGE? Linux distro dependencies like in Ubuntu image Prebuilt dependencies for app useful in containers Everything is packed up as layers Images are read-only
  • 23. HOW TO BUILD OWN IMAGE?HOW TO BUILD OWN IMAGE?
  • 24. FOLLOW DOCKERFILE SYNTAXFOLLOW DOCKERFILE SYNTAX FROM <image>[:<tag>] # base image RUN <command> # runs command only once during build CMD command param1 param2 # runs on container boot EXPOSE <port> [<port>/<protocol>...] ENV <key> <value> # only inside a container ADD [--chown=<user>:<group>] <src>... <dest> COPY <src>... <dest> ENTRYPOINT command param1 param2 # container will run as an ex VOLUME ["/data"] USER <user>[:<group>] # who runs executables WORKDIR /path # where run executables HEALTHCHECK [OPTIONS] CMD command
  • 25. $ docker build . Sending build context to Docker daemon 15.36 kB Step 1/4 : FROM alpine:3.2 ---> 31f630c65071 Step 2/4 : MAINTAINER forest.gump@example.com ---> Using cache ---> 2a1c91448f5f Step 3/4 : RUN apk update && apk add apache2 && rm -r /var/cac ---> Using cache ---> 21ed6e7fbb73 Step 4/4 : CMD apache2 ---> Using cache ---> 7ea8aef582cc Successfully built 7ea8aef582cc
  • 26. RUNNING CONTAINERRUNNING CONTAINER $ docker run -it ubuntu:14.04 /bin/bash $ docker run -it tomcat -d -p 8080:80
  • 27. DOCKER-COMPOSE - TO THE RESCUEDOCKER-COMPOSE - TO THE RESCUE version: '3' services: web: image: apache links: - database ports: - '8080:80' volumes: - ./project:/var/www:rw database: image: mysql $ docker-compose up
  • 29. BITBUCKET PIPELINESBITBUCKET PIPELINES similar syntax to docker-compose.yml limit of only one container with mounted codebase codebase can be mounted into different containers with steps services are the only way of having multiple containers services are reachable through network only
  • 30. image: alpine:latest pipelines: default: - step: image: node:8.9.4 caches: - node_modules script: - npm run build branches: master: - step: script: - ./generateReleaseNotes.sh
  • 31. GITLAB PIPELINESGITLAB PIPELINES can organise chain of processes which leads to release
  • 32. GITLAB PIPELINESGITLAB PIPELINES limit of only one container with mounted codebase codebase can be mounted into different containers with jobs services are the only way of having multiple containers services are reachable through network only
  • 33. image: php:latest services: - mysql:5.7 variables: MYSQL_DATABASE: fancyDB MYSQL_ROOT_PASSWORD: secret DB_HOST: mysql DB_USERNAME: root stages: - test - deploy
  • 34. SECURITY - GET RID OF ROOTSECURITY - GET RID OF ROOT PRIVILEGESPRIVILEGES follow the principle of least privilege Docker requires root privileges to run, containers themselves do not process running in a container is no different from other process many images just run as root and leave it up to you
  • 35. $ docker run -v /root:/tmp/rootdir alpine:latest ls -la /tmp/r drwxr-xr-x+ 126 root root 4032 Jun 21 13:43 . drwxr-xr-x 7 root root 224 Jun 15 12:31 .. -rw-r--r-- 1 root root 266 Nov 26 2017 secretFile
  • 36. FROM anyimage:latest RUN groupadd -g 999 appuser && useradd -r -u 999 -g appuser appuser USER appuser
  • 38. ELASTIC CONTAINERELASTIC CONTAINER SERVICE (ECS)SERVICE (ECS) user manages clusters of containers cluster defines type of underlying EC2 instances one underlying instance can run many containers it's still up to user to administrate instances
  • 39. FARGATEFARGATE user doesn't have to manage cluster and instances user precises only CPU/memory requirements containers are created on AWS managed instances Kubernetes support coming in 2018
  • 40. NEXT STEP - ORCHESTRASTIONNEXT STEP - ORCHESTRASTION Docker Swarm Kubernetes AWS/Azure/Google solutions
  • 42. THANK YOU FORTHANK YOU FOR YOUR TIMEYOUR TIME Slides are available on https://michailw.github.io/talks/docker/