7. At the beginning
• One goal
• Linux only
• Intel CPU only
• A big and fat binnary
8. And now?
• Linux and Windows containers
• Running on Mac, Windows and Linux
• Multi Architecture (intel, armv5-8, ppc, i386)
• Split into many components
• Component standardisation (OCI, CNCF)
• Adopted by a large majority of cloud
providers
9. What is a container?
• An isolated space where an application run
• Contain everything needed to run the
application (libs, binaries, etc.)
• Own its dedicated network stack, users,
process, etc.
• Share the host kernel
• Could have some resource restriction (CPU,
Ram, etc.)
12. What is an
image?
• An union of layers
• Each layers are immutable
• Each layers are reusable
13. Let’s build a Docker image
Base image
Environnent variable
Variable set during build
Working directory
Copy files into image
Command executed during build
Copy folder into image
Default command that will be
executed during a docker run
14. How to transform our file into an image?
❯ docker build -t myapp:v1.0.0 --build-arg NODE_ENV=development .
Command to build an image
Give a name and tag to the image
Set a build variable
Build context
If the Dockerfile file has another name or is located elsewhere, it must be specified with:
-f .docker/Dockerfile
Warning : the context build is always the last parameter
15. How to run a container?
- I can’t access my app from my browser
- Ctr+C do not stop my app
- The container name will be randomly generated - ex: goofy_kapitsa
❯ docker run myapp:v1.0.0
Command to run a container Image name and tag
16. How to run a container?
❯ docker run –ti -p 8080:80 --name myapp myapp:v1.0.0
Run in interactive mode and with a tty
Link container port 80 to host port 8080
Give the name myapp to the container
17. How to run a container?
❯ docker run –d -p 8080:80 --name myapp myapp:v1.0.0
Run container in background
❯ docker run –ti –p 8080:80 --name myapp --rm myapp:v1.0.0 bash
Automatically remove the container when stopped
Change the default command (CMD)
19. Docker Engine
• Client-Server application for managing
• Images
• Containers
• Networks
• Volumes
• Has a REST API and a CLI
20. Volume
• Keep data outside the container
• Share data with host
This Photo by Unknown Author is licensed under CC BY-SA-NC
21. Share folder/files between host and container
❯ docker run -ti --rm -v `pwd`/mydir:/data ubuntu
Command for using a volume
Local directory on host Directory in the container
Be careful when mounting a file!
Changes to file may not be reflected in container
Ex: sed, vim, VS Code
22. Using a volume
❯ docker volume create mydata
❯ docker run -ti --rm -v mydata:/data ubuntu
Command to manage volume Volume name
Volume name instead of a path
23. Network
• Allows you to:
• create isolated network
• Reproduce production network topology
• Container can communicate with each other
using by name, id or alias
• Many network type/driver available:
• Bridge (default)
• Internal
• None
• Host
24. Internal network
❯ docker network create --internal intnet
❯ docker run --network intnet curlimages/curl -m3 https://google.com
╰─❯ curl: (28) Resolving timed out after 3002 milliseconds
Command to manage networks Network type Network name
Attach the container to the intent network
25. Intra-container communication
❯ docker network create --driver bridge mynet
❯ docker run -d --network mynet --name nginx --network-alias web nginx
❯ docker run --rm --network mynet curlimages/curl -m3 http://web
Use a specific network driver
Adds an alias to the container in networks it is connected
Container name or ID also works
26. Other useful network
❯ docker run --rm --network none curl -m3 https://google.com
❯ docker run –d --network host nginx
No network isolation between host and container
Without network
28. Let’s build a docker compose file
DEPRECATED - No more used
Services definition
Networks definition
Volumes definition
29. Let’s build a docker compose file
Service name and its name on the network
Container image
If the container crash, docker will restart it
List of volumes to attach to the container
List of environment variables
List of networks to attach to the container
30. Let’s build a docker compose file
Override default image command
You can attach a volume to a directory in another volume
Definition for building the image
Create a dependency on another service
List of port to link to the host
31. Let’s build a docker compose file
On a separate network from the database
32. How to use a compose file?
❯ docker compose ps -a
List the containers created by compose Including those stopped
❯ docker compose logs -f [name of service(s)]
Show logs And show new logs as they come
❯ docker compose up –d [name of service(s)]
Command for compose Start service(s)
In background
34. Useful commands
❯ docker login / docker login kumojin.azurecr.io
Connect Docker to a registry
Pull an image locally
Push a local image to a registry
❯ docker push jmaitrehenry/myimage
❯ docker pull kumojin.azurecr.io/myapp/api:v1.0.0
Connect to a specific registry
36. For what?
• Container supply and placement
• Health check mechanism and metrics
• Unavailability and scalability management
• Deployment management
• Service discovery and network management
• And more!