docker --versionDocker version 29.1.5, build 0e6fee6
Découvrir les conteneurs avec Docker
2026-02-01
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.
Donner le goût des conteneurs en pratiquant :
run, ps, stop, rmCe TP n’est pas un TP de production. Il vise à construire une intuition correcte des conteneurs.
Si l’installation de Docker localement est difficile, vous pouvez utiliser un environnement en ligne tel que Play with Docker ou Katacoda.
Les commandes présentées dans ce TP utilisent les formes longues des options pour plus de clarté. Formes longues ↔︎ courtes
-d-p-v-i-t-eCréer un dossier de travail et s’y positionner ($TP_DIR="~/tp0-containers-101") :
Nettoyage optionnel des restes d’exécutions précédentes :
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 :
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é :
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 :
HTTP/1.1 200 OK [1mServer[0m: nginx/1.28.1 [1mDate[0m: Fri, 30 Jan 2026 16:10:31 GMT [1mContent-Type[0m: text/html [1mContent-Length[0m: 615 [1mLast-Modified[0m: Tue, 23 Dec 2025 18:40:33 GMT [1mConnection[0m: keep-alive [1mETag[0m: “694ae221-267” [1mAccept-Ranges[0m: bytes
<!DOCTYPE html>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 :
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 :
Les conteneurs y compris arrêtés peuvent être listés avec :
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 :
Un conteneur = un service/processus isolé
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 :
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) :
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.
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.
Nettoyage :
Les données ne vivent pas dans le conteneur, il doit être éphémère
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.
Dans le conteneur, exécuter les commandes suivantes pour explorer le système, créer un fichier et installer curl.
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 :
Ce qui n’est pas dans une image est perdu
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).
Construire l’image Docker à partir d’un Dockerfile dans le dossier courant (.) avec le tag tp0-ubuntu-curl :
Tester en mode interactif en exécutant la commande curl --max-time 30 --include https://example.com dans le conteneur :
la commande peut aussi être passée en paramètre du docker run :
% 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
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
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.
Construire l’image Docker depuis le dossier app/ avec le 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 :
468a0d8e434cd00c1684b6f2646c16e374252f58475251c100d1ef0f1e7395be
Tester l’application avec curl depuis l’hôte :
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) :
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 :
Lancer le conteneur de l’application Python dans ce réseau :
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 :
Nettoyage :
Les conteneurs communiquent via des réseaux virtuels et des noms DNS internes
Les conteneurs permettent de déployer des applications complexes de manière reproductible et en isolant les différentes parties.