Pratique : Container 101

Découvrir les conteneurs avec Docker

Practice
Containers
Docker
Exercices pratiques pour découvrir Docker à travers des cas simples et progressifs.
Auteur
Affiliations

Université de Toulon

LIS UMR CNRS 7020

Date de publication

2026-02-01

Environnement et reproductibilite

Jupyter Kernel: bash

🖥️ Env Ubuntu 24.04.3 LTS / x86_64 • 🐳 Docker Client 29.1.5 / Server 29.1.5 • 🌿 Git Branch @ 7b914bd

Ce support a été généré par Quarto : les cellules sont exécutées par le noyau indiqué lors du rendu.

Certaines parties ont été rédigées avec l’assistance d’un modèle de langage ; le contenu a été relu et validé par l’auteur.

Objectif du TP

Astuce

Donner le goût des conteneurs en pratiquant :

  • Les commandes essentielles : run, ps, stop, rm
  • Les ports, volumes et réseaux
  • Le mode interactif (exploration)
  • La création d’une image simple avec un Dockerfile

Ce TP n’est pas un TP de production. Il vise à construire une intuition correcte des conteneurs.

Prérequis

  • Docker installé et fonctionnel :
docker --version
Docker version 29.1.5, build 0e6fee6
  • Accès à un terminal (bash/zsh)
  • Éditeur de texte minimal
Avertissement

Si l’installation de Docker localement est difficile, vous pouvez utiliser un environnement en ligne tel que Play with Docker ou Katacoda.

Astuce

Les commandes présentées dans ce TP utilisent les formes longues des options pour plus de clarté. Formes longues ↔︎ courtes

  • –detach : -d
  • –publish : -p
  • –volume : -v
  • –interactive : -i
  • –tty : -t
  • –env : -e
  • –name : (pas de forme courte distincte)
  • –rm : (forme longue déjà explicite)

Setup initial

Créer un dossier de travail et s’y positionner ($TP_DIR="~/tp0-containers-101") :

Nettoyage optionnel des restes d’exécutions précédentes :

docker rm --force tp0-nginx tp0-app 2>/dev/null || true
docker network rm tp0-net 2>/dev/null || true
docker image rm tp0-app:0.1 2>/dev/null || true

Exercice 1 — Lancer un premier conteneur

Objectif

Voir un conteneur en cours d’exécution.

La commande suivante lance un conteneur nginx (serveur web) en arrière-plan, nommé tp0-nginx, exposant le port 80 du conteneur sur le port 8080 de l’hôte :

docker run --detach \
  --name tp0-nginx \
  --publish 8080:80 \
  nginx:stable
Unable to find image 'nginx:stable' locally
stable: Pulling from library/nginx

7621fff433f2: Pulling fs layer 
6697c8ec7c25: Pulling fs layer 
ae9b786964d0: Pulling fs layer 
a5163318194d: Pulling fs layer 
998d5e4721ac: Pulling fs layer 
8d96ce5090ec: Pulling fs layer 7621fff433f2: Download complete 
3c43a66c8ef2: Download complete 
212c51a5503f: Downloading  1.049MB/2.816MB212c51a5503f: Downloading  2.097MB/2.816MBae9b786964d0: Download complete 6697c8ec7c25: Downloading   1.21kB/1.21kB8d96ce5090ec: Downloading     629B/629Ba5163318194d: Download complete 212c51a5503f: Download complete 6697c8ec7c25: Download complete 8d96ce5090ec: Download complete 998d5e4721ac: Downloading  1.049MB/33.04MB998d5e4721ac: Downloading  1.049MB/33.04MB998d5e4721ac: Downloading  2.097MB/33.04MB998d5e4721ac: Downloading  2.097MB/33.04MB998d5e4721ac: Downloading  3.146MB/33.04MB998d5e4721ac: Downloading  4.194MB/33.04MB998d5e4721ac: Downloading  6.291MB/33.04MB998d5e4721ac: Downloading  6.291MB/33.04MB998d5e4721ac: Downloading  6.291MB/33.04MB998d5e4721ac: Downloading   7.34MB/33.04MB998d5e4721ac: Downloading   7.34MB/33.04MB998d5e4721ac: Downloading  8.389MB/33.04MB998d5e4721ac: Downloading  9.437MB/33.04MB998d5e4721ac: Downloading  9.437MB/33.04MB998d5e4721ac: Downloading  9.437MB/33.04MB998d5e4721ac: Downloading  10.49MB/33.04MB998d5e4721ac: Downloading  11.53MB/33.04MB998d5e4721ac: Downloading  11.53MB/33.04MB998d5e4721ac: Downloading  13.63MB/33.04MB998d5e4721ac: Downloading  14.68MB/33.04MB998d5e4721ac: Downloading  15.73MB/33.04MB998d5e4721ac: Downloading  15.73MB/33.04MB998d5e4721ac: Downloading  15.73MB/33.04MB998d5e4721ac: Downloading  16.78MB/33.04MB998d5e4721ac: Downloading  17.83MB/33.04MB998d5e4721ac: Downloading  18.87MB/33.04MB998d5e4721ac: Downloading  18.87MB/33.04MB998d5e4721ac: Downloading  19.92MB/33.04MB998d5e4721ac: Downloading  22.02MB/33.04MB998d5e4721ac: Downloading  22.02MB/33.04MB998d5e4721ac: Downloading  23.07MB/33.04MB998d5e4721ac: Downloading  24.12MB/33.04MB998d5e4721ac: Downloading  25.17MB/33.04MB998d5e4721ac: Downloading  26.21MB/33.04MB998d5e4721ac: Downloading  26.21MB/33.04MB998d5e4721ac: Downloading  27.26MB/33.04MB998d5e4721ac: Downloading  29.36MB/33.04MB998d5e4721ac: Downloading  29.36MB/33.04MB998d5e4721ac: Downloading  29.36MB/33.04MB998d5e4721ac: Downloading  29.36MB/33.04MB998d5e4721ac: Downloading  30.41MB/33.04MB998d5e4721ac: Downloading  31.46MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Downloading  32.51MB/33.04MB998d5e4721ac: Download complete 998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s998d5e4721ac: Extracting 1 s8d96ce5090ec: Extracting 1 s998d5e4721ac: Pull complete 8d96ce5090ec: Pull complete 7621fff433f2: Pull complete a5163318194d: Pull complete 6697c8ec7c25: Pull complete ae9b786964d0: Pull complete Digest: sha256:0a1f2fb3231e1c0c1360ba383a2d02728b5912bb13eb87406839e2002e472fae
Status: Downloaded newer image for nginx:stable
508f457bd368ed3b66340750946c2ac68d89498f55c4b729aa224f5a68dc0a3b

Vérifier qu’il est bien lancé :

docker container ls
CONTAINER ID   IMAGE          COMMAND                  CREATED                  STATUS                  PORTS                                         NAMES
508f457bd368   nginx:stable   "/docker-entrypoint.…"   Less than a second ago   Up Less than a second   0.0.0.0:8080->80/tcp, [::]:8080->80/tcp       tp0-nginx
9f773e64f3cc   postgres:17    "docker-entrypoint.s…"   2 hours ago              Up 2 hours              0.0.0.0:5432->5432/tcp, [::]:5432->5432/tcp   db

Il est accessible via le port 8080 de l’hôte avec un navigateur web ou curl :

Tester :

curl --max-time 30 --include http://localhost:8080

HTTP/1.1 200 OK Server: nginx/1.28.1 Date: Fri, 30 Jan 2026 16:10:31 GMT Content-Type: text/html Content-Length: 615 Last-Modified: Tue, 23 Dec 2025 18:40:33 GMT Connection: keep-alive ETag: “694ae221-267” Accept-Ranges: bytes

<!DOCTYPE html> Welcome to nginx!

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

Les 10 derniers logs du conteneur peuvent être consultés avec :

docker logs tp0-nginx --tail 10
2026/01/30 16:10:31 [notice] 1#1: start worker process 42
2026/01/30 16:10:31 [notice] 1#1: start worker process 43
2026/01/30 16:10:31 [notice] 1#1: start worker process 44
2026/01/30 16:10:31 [notice] 1#1: start worker process 45
2026/01/30 16:10:31 [notice] 1#1: start worker process 46
2026/01/30 16:10:31 [notice] 1#1: start worker process 47
2026/01/30 16:10:31 [notice] 1#1: start worker process 48
2026/01/30 16:10:31 [notice] 1#1: start worker process 49
2026/01/30 16:10:31 [notice] 1#1: start worker process 50
10.89.8.221 - - [30/Jan/2026:16:10:31 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/8.18.0" "-"

Le conteneur peut être arrêté avec :

docker stop tp0-nginx
tp0-nginx

Les conteneurs y compris arrêtés peuvent être listés avec :

docker container ls --all
CONTAINER ID   IMAGE            COMMAND                  CREATED        STATUS                              PORTS                                         NAMES
508f457bd368   nginx:stable     "/docker-entrypoint.…"   1 second ago   Exited (0) Less than a second ago                                                 tp0-nginx
9f773e64f3cc   postgres:17      "docker-entrypoint.s…"   2 hours ago    Up 2 hours                          0.0.0.0:5432->5432/tcp, [::]:5432->5432/tcp   db
41196afc533e   restjpa:latest   "java -jar app.jar"      2 days ago     Exited (1) About a minute ago                                                     notebook-containers-intro-sample-java-restjpa-app-1

et supprimé avec :

docker rm --force tp0-nginx
tp0-nginx
ImportantRappel

Un conteneur = un service/processus isolé

Exercice 2 — Volumes : partager des fichiers

Objectif

Pour relier le système de fichier de l’hôte et celui du conteneur, on utilise des volumes.

Créer un dossier www/ sur l’hôte avec une page HTML simple :

mkdir -p www
echo "<h1>Hello from host</h1>" > www/index.html

Lancer un serveur web nginx en montant le dossier www/ de l’hôte dans le dossier /usr/share/nginx/html du conteneur (en lecture seule avec :ro) :

docker run --detach \
  --name tp0-nginx \
  --publish 8080:80 \
  --volume "$PWD/www":/usr/share/nginx/html:ro \
  nginx:stable

Il est accessible via le port 8080 de l’hôte avec un navigateur web ou curl :

curl est utilisé ici pour afficher les headers HTTP et le contenu de la page.

curl --max-time 30 --include http://localhost:8080
HTTP/1.1 200 OK


Server: nginx/1.28.1


Date: Fri, 30 Jan 2026 16:10:40 GMT


Content-Type: text/html


Content-Length: 25


Last-Modified: Fri, 30 Jan 2026 16:10:33 GMT


Connection: keep-alive


ETag: "697cd7f9-19"


Accept-Ranges: bytes





<h1>Hello from host</h1>

Modifier www/index.html sur l’hôte et rafraîchir la page ou relancer curl.

echo "<h1>Hello from host - updated</h1>" > www/index.html
curl --max-time 30 --include http://localhost:8080

Nettoyage :

ImportantRappel

Les données ne vivent pas dans le conteneur, il doit être éphémère

Exercice 3 — Mode interactif et installation

Il est important de comprendre la différence entre un conteneur et une image. Il est possible d’executer des conteneurs en mode interactif pour explorer leur contenu et interagir avec eux.

Il est déconseillé d’installer des logiciels directement dans un conteneur en production.

docker run --interactive --tty --rm ubuntu:22.04

Dans le conteneur, exécuter les commandes suivantes pour explorer le système, créer un fichier et installer curl.

cat /etc/os-release
uname -a
echo "Hello from inside the container" > /tmp/hello.txt
apt update && apt install -y curl
curl --max-time 30 --include https://example.com

quitter le conteneur avec la commande exit (ou Ctrl+D).

Unable to find image 'ubuntu:22.04' locally
22.04: Pulling from library/ubuntu

e4eb0721af32: Downloading  1.049MB/1.98MBe4eb0721af32: Downloading  1.049MB/1.98MBe4eb0721af32: Download complete Digest: sha256:c7eb020043d8fc2ae0793fb35a37bff1cf33f156d4d4b12ccc7f3ef8706c38b1
Status: Downloaded newer image for ubuntu:22.04
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package openssl.
(Reading database ... 4393 files and directories currently installed.)
Preparing to unpack .../00-openssl_3.0.2-0ubuntu1.21_amd64.deb ...
Unpacking openssl (3.0.2-0ubuntu1.21) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../01-ca-certificates_20240203~22.04.1_all.deb ...
Unpacking ca-certificates (20240203~22.04.1) ...
Selecting previously unselected package libnghttp2-14:amd64.
Preparing to unpack .../02-libnghttp2-14_1.43.0-1ubuntu0.2_amd64.deb ...
Unpacking libnghttp2-14:amd64 (1.43.0-1ubuntu0.2) ...
Selecting previously unselected package libpsl5:amd64.
Preparing to unpack .../03-libpsl5_0.21.0-1.2build2_amd64.deb ...
Unpacking libpsl5:amd64 (0.21.0-1.2build2) ...
Selecting previously unselected package publicsuffix.
Preparing to unpack .../04-publicsuffix_20211207.1025-1_all.deb ...
Unpacking publicsuffix (20211207.1025-1) ...
Selecting previously unselected package libbrotli1:amd64.
Preparing to unpack .../05-libbrotli1_1.0.9-2build6_amd64.deb ...
Unpacking libbrotli1:amd64 (1.0.9-2build6) ...
Selecting previously unselected package libsasl2-modules-db:amd64.
Preparing to unpack .../06-libsasl2-modules-db_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
Unpacking libsasl2-modules-db:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Selecting previously unselected package libsasl2-2:amd64.
Preparing to unpack .../07-libsasl2-2_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
Unpacking libsasl2-2:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Selecting previously unselected package libldap-2.5-0:amd64.
Preparing to unpack .../08-libldap-2.5-0_2.5.19+dfsg-0ubuntu0.22.04.1_amd64.deb ...
Unpacking libldap-2.5-0:amd64 (2.5.19+dfsg-0ubuntu0.22.04.1) ...
Selecting previously unselected package librtmp1:amd64.
Preparing to unpack .../09-librtmp1_2.4+20151223.gitfa8646d.1-2build4_amd64.deb ...
Unpacking librtmp1:amd64 (2.4+20151223.gitfa8646d.1-2build4) ...
Selecting previously unselected package libssh-4:amd64.
Preparing to unpack .../10-libssh-4_0.9.6-2ubuntu0.22.04.5_amd64.deb ...
Unpacking libssh-4:amd64 (0.9.6-2ubuntu0.22.04.5) ...
Selecting previously unselected package libcurl4:amd64.
Preparing to unpack .../11-libcurl4_7.81.0-1ubuntu1.21_amd64.deb ...
Unpacking libcurl4:amd64 (7.81.0-1ubuntu1.21) ...
Selecting previously unselected package curl.
Preparing to unpack .../12-curl_7.81.0-1ubuntu1.21_amd64.deb ...
Unpacking curl (7.81.0-1ubuntu1.21) ...
Selecting previously unselected package libldap-common.
Preparing to unpack .../13-libldap-common_2.5.19+dfsg-0ubuntu0.22.04.1_all.deb ...
Unpacking libldap-common (2.5.19+dfsg-0ubuntu0.22.04.1) ...
Selecting previously unselected package libsasl2-modules:amd64.
Preparing to unpack .../14-libsasl2-modules_2.1.27+dfsg2-3ubuntu1.2_amd64.deb ...
Unpacking libsasl2-modules:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Setting up libpsl5:amd64 (0.21.0-1.2build2) ...
Setting up libbrotli1:amd64 (1.0.9-2build6) ...
Setting up libsasl2-modules:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Setting up libnghttp2-14:amd64 (1.43.0-1ubuntu0.2) ...
Setting up libldap-common (2.5.19+dfsg-0ubuntu0.22.04.1) ...
Setting up libsasl2-modules-db:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Setting up librtmp1:amd64 (2.4+20151223.gitfa8646d.1-2build4) ...
Setting up libsasl2-2:amd64 (2.1.27+dfsg2-3ubuntu1.2) ...
Setting up libssh-4:amd64 (0.9.6-2ubuntu0.22.04.5) ...
Setting up openssl (3.0.2-0ubuntu1.21) ...
Setting up publicsuffix (20211207.1025-1) ...
Setting up libldap-2.5-0:amd64 (2.5.19+dfsg-0ubuntu0.22.04.1) ...
Setting up ca-certificates (20240203~22.04.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.34.0 /usr/local/share/perl/5.34.0 /usr/lib/x86_64-linux-gnu/perl5/5.34 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.34 /usr/share/perl/5.34 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Updating certificates in /etc/ssl/certs...
146 added, 0 removed; done.
Setting up libcurl4:amd64 (7.81.0-1ubuntu1.21) ...
Setting up curl (7.81.0-1ubuntu1.21) ...
Processing triggers for libc-bin (2.35-0ubuntu3.11) ...
Processing triggers for ca-certificates (20240203~22.04.1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

Linux e25efe2e424a 6.18.6-200.fc43.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Jan 18 18:57:00 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0100   513    0   513    0     0   1533      0 --:--:-- --:--:-- --:--:--  1531
HTTP/2 200 
date: Fri, 30 Jan 2026 16:11:00 GMT
content-type: text/html
cf-ray: 9c623e1fcdcc3772-CDG
last-modified: Fri, 30 Jan 2026 05:47:18 GMT
allow: GET, HEAD
accept-ranges: bytes
age: 1541
cf-cache-status: HIT
server: cloudflare

<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div></body></html>

Relancer :

docker run --interactive --tty --rm ubuntu:22.04 bash
cat /tmp/hello.txt   # ❌ disparu
curl --max-time 30 --include https://example.com  # ❌ curl non installé
ImportantRappel

Ce qui n’est pas dans une image est perdu

Exercice 4 — Créer une image simple

Pour rendre l’installation reproductible et persistante, il faut créer une image. L’approche standard est d’écrire un fichier Dockerfile décrivant l’image.

Créer un Dockerfile qui installe curl (RUN) dans une image basée sur ubuntu:22.04 (FROM) et qui lance bash par défaut (CMD).

Dockerfile
FROM ubuntu:22.04
RUN apt update && apt install -y curl
CMD ["bash"]

Construire l’image Docker à partir d’un Dockerfile dans le dossier courant (.) avec le tag tp0-ubuntu-curl :

docker build --tag tp0-ubuntu-curl .

Tester en mode interactif en exécutant la commande curl --max-time 30 --include https://example.com dans le conteneur :

docker run --interactive --tty --rm tp0-ubuntu-curl

la commande peut aussi être passée en paramètre du docker run :

docker run --rm tp0-ubuntu-curl \
  curl --max-time 30 --include https://example.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/2 200 
date: Fri, 30 Jan 2026 16:11:24 GMT
content-type: text/html
cf-ray: 9c623eb30a6ed0b6-CDG
last-modified: Fri, 30 Jan 2026 05:47:18 GMT
allow: GET, HEAD
accept-ranges: bytes
age: 1565
cf-cache-status: HIT
server: cloudflare

<!doctype html><html lang="en"><head><title>Example Domain</title><meta name="viewport" content="width=device-width, initial-scale=1"><style>body{background:#eee;width:60vw;margin:15vh auto;font-family:system-ui,sans-serif}h1{font-size:1.5em}div{opacity:0.8}a:link,a:visited{color:#348}</style><body><div><h1>Example Domain</h1><p>This domain is for use in documentation examples without needing permission. Avoid use in operations.<p><a href="https://iana.org/domains/example">Learn more</a></div></body></html>
100   513    0   513    0     0   2768      0 --:--:-- --:--:-- --:--:--  2772

Exercice 5 — Construire une image applicative

En suivant la même approche, il est possible de créer une image contenant une application Python simple.

Créer une structure de dossiers app/ avec une application serveur Web minimale en Python :

app

├── app.py

└── Dockerfile



1 directory, 2 files

L’application Python

app/app.py
from http.server import SimpleHTTPRequestHandler, HTTPServer

server = HTTPServer(('0.0.0.0', 5000), SimpleHTTPRequestHandler)
print("Listening on 5000")
server.serve_forever()

Un fichier Dockerfile qui construit l’image de l’application Python en utilisant l’image officielle python:3.11-slim comme base, en copiant le fichier app.py dans le conteneur et en définissant la commande par défaut pour exécuter l’application.

app/Dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY app.py .
CMD ["python", "app.py"]

Construire l’image Docker depuis le dossier app/ avec le tag tp0-app:0.0.1 :

docker build --tag tp0-app:0.0.1 .
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile:
#1 transferring dockerfile: 181B done
#1 DONE 0.2s

#2 [internal] load metadata for docker.io/library/python:3.11-slim
#2 ...

#3 [auth] library/python:pull token for registry-1.docker.io
#3 DONE 0.0s

#2 [internal] load metadata for docker.io/library/python:3.11-slim
#2 DONE 2.4s

#4 [internal] load .dockerignore
#4 transferring context:
#4 transferring context: 2B done
#4 DONE 0.2s

#5 [internal] load build context
#5 transferring context: 282B done
#5 DONE 0.3s

#6 [1/3] FROM docker.io/library/python:3.11-slim@sha256:5be45dbade29bebd6886af6b438fd7e0b4eb7b611f39ba62b430263f82de36d2
#6 resolve docker.io/library/python:3.11-slim@sha256:5be45dbade29bebd6886af6b438fd7e0b4eb7b611f39ba62b430263f82de36d2 0.2s done
#6 DONE 0.6s

#6 [1/3] FROM docker.io/library/python:3.11-slim@sha256:5be45dbade29bebd6886af6b438fd7e0b4eb7b611f39ba62b430263f82de36d2
#6 sha256:0b2bf04f68e9f306a8a83f57c6ced322a23968bf3d5acebc07e055c090240826 0B / 250B 0.2s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 0B / 14.36MB 0.2s
#6 sha256:5b09819094bb89d5b2416ff2fb03f68666a5372c358cfd22f2b62d7f6660d906 0B / 1.29MB 0.2s
#6 sha256:0b2bf04f68e9f306a8a83f57c6ced322a23968bf3d5acebc07e055c090240826 250B / 250B 0.3s done
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 1.05MB / 14.36MB 0.9s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 2.10MB / 14.36MB 1.1s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 3.15MB / 14.36MB 1.2s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 4.19MB / 14.36MB 1.4s
#6 sha256:5b09819094bb89d5b2416ff2fb03f68666a5372c358cfd22f2b62d7f6660d906 1.29MB / 1.29MB 1.5s done
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 5.24MB / 14.36MB 1.7s
#6 extracting sha256:5b09819094bb89d5b2416ff2fb03f68666a5372c358cfd22f2b62d7f6660d906
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 7.34MB / 14.36MB 1.8s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 8.39MB / 14.36MB 2.0s
#6 extracting sha256:5b09819094bb89d5b2416ff2fb03f68666a5372c358cfd22f2b62d7f6660d906 0.3s done
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 9.44MB / 14.36MB 2.1s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 10.49MB / 14.36MB 2.3s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 11.53MB / 14.36MB 2.4s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 12.58MB / 14.36MB 2.6s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 13.63MB / 14.36MB 2.7s
#6 sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 14.36MB / 14.36MB 5.2s done
#6 DONE 5.9s

#6 [1/3] FROM docker.io/library/python:3.11-slim@sha256:5be45dbade29bebd6886af6b438fd7e0b4eb7b611f39ba62b430263f82de36d2
#6 extracting sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2
#6 extracting sha256:3e731abb5c1dd05aef62585d392d31ad26089dc4c031730e5ab0225aef80b3f2 0.7s done
#6 DONE 6.6s

#6 [1/3] FROM docker.io/library/python:3.11-slim@sha256:5be45dbade29bebd6886af6b438fd7e0b4eb7b611f39ba62b430263f82de36d2
#6 extracting sha256:0b2bf04f68e9f306a8a83f57c6ced322a23968bf3d5acebc07e055c090240826 0.1s done
#6 DONE 6.7s

#7 [2/3] WORKDIR /app
#7 DONE 0.1s

#8 [3/3] COPY app.py .
#8 DONE 0.3s

#9 exporting to image
#9 exporting layers
#9 exporting layers 0.6s done
#9 exporting manifest sha256:294988a9de47980b27d1af1d79b9c7e2e18d5fbde0fac72c5f60e68a0b5f8b3a 0.1s done
#9 exporting config sha256:6876fdfa975aa1279325393efcbf7273b4500471c6912f54ec0453dafbbe2e2b 0.1s done
#9 exporting attestation manifest sha256:a216cf6ee8f1198f51fe7af6fc968e1ecd7ed2b694a0fac793d206e8425309ed 0.1s done
#9 exporting manifest list sha256:07a09aef52f528a991bbbe16e3f426c1df8dd023694732785f0981e33155af69
#9 exporting manifest list sha256:07a09aef52f528a991bbbe16e3f426c1df8dd023694732785f0981e33155af69 0.1s done
#9 naming to docker.io/library/tp0-app:0.0.1 0.0s done
#9 unpacking to docker.io/library/tp0-app:0.0.1
#9 unpacking to docker.io/library/tp0-app:0.0.1 0.2s done
#9 DONE 1.2s

Exécuter le conteneur en mappant le port 5000 du conteneur (sur lequel l’application écoute) sur le port 5000 de l’hôte :

docker run --detach \
  --name tp0-app \
  --publish 5000:5000 \
  tp0-app:0.0.1
468a0d8e434cd00c1684b6f2646c16e374252f58475251c100d1ef0f1e7395be

Tester l’application avec curl depuis l’hôte :

curl --max-time 30 --include http://localhost:5000
HTTP/1.0 200 OK


Server: SimpleHTTP/0.6 Python/3.11.14


Date: Fri, 30 Jan 2026 16:11:40 GMT


Content-type: text/html; charset=utf-8


Content-Length: 224





<!DOCTYPE HTML>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Directory listing for /</title>

</head>

<body>

<h1>Directory listing for /</h1>

<hr>

<ul>

<li><a href="app.py">app.py</a></li>

</ul>

<hr>

</body>

</html>

Nettoyer le conteneur (arrêt et suppression) :

docker stop tp0-app
docker rm tp0-app
tp0-app
tp0-app

Exercice 6 — (Optionnel) Réseaux Docker

Il est possible de faire fonctionner plusieurs conteneurs ensemble via un réseau Docker. Dans cet exercice, nous allons créer un réseau Docker et y connecter le conteneur de l’application Python et et autre conteneur curl pour tester l’application.

Créer un réseau (virtuel) Docker nommé tp0-net :

docker network create tp0-net
61498b4104edeeabd861138ea7bb0d0714f89481119d127121e20f5ba22de0e4

Lancer le conteneur de l’application Python dans ce réseau :

docker run --detach \
  --name tp0-app \
  --network tp0-net \
  tp0-app:0.0.1
494e025fc1be1432b704ec3dee0e6598dbb25bcaef0bd40996ed35ef4149d8dc

Tester l’application avec un conteneur curl connecté au même réseau Docker, en utilisant le nom du conteneur tp0-app comme hostname pour le service :

#| echo: true
#| output: asis
docker run --rm \
  --network tp0-net \
  curlimages/curl --max-time 30 --include http://tp0-app:5000

Nettoyage :

ImportantRappel

Les conteneurs communiquent via des réseaux virtuels et des noms DNS internes

Synthèse

ImportantRappel
  • Un conteneur n’est pas un mini-serveur, C’est un **processus isolé, créé à partir d’une image
  • Une–include image est un modèle immuable pour créer des conteneurs à l’aide d’un Dockerfile qui décrit sa construction et peut être versionné.
  • Les données doivent être stockées en dehors du conteneur via des volumes
  • Les conteneurs communiquent via des réseaux virtuels

Les conteneurs permettent de déployer des applications complexes de manière reproductible et en isolant les différentes parties.

Réutilisation