Hello
Cycle de vie, volumes, réseaux, ressources, bonnes pratiques
2026-01-20
À l’issue de ce cours, vous devez être capables de :
Un conteneur est une instance d’une image. L’image est un artefact immuable (voir le cours “Image”). Le conteneur est un processus isolé qui tourne sur le noyau de l’hôte.
Astuce
[registre/]nom[:tag] (ex: docker.io/library/nginx:1.23).
latest est utilisé par défaut.nginx:1, nginx:1.29,nginx:mainline, nginx:latest, nginx:f3524ef8b874 peuvent référencer la même image.linux/amd64, linux/arm64/v8, windows/amd64.Exécution simple
docker run crée et démarre un conteneur à partir d’une image.--rm pour supprimer automatiquement après).docker run [OPTIONS] IMAGE [COMMAND] [ARG...].-d)docker run -d démarre un conteneur en arrière-plan (détaché --detach).ps)docker ps liste les conteneurs en cours d’exécution.-a liste tous les conteneurs (y compris arrêtés).stop) / démarrer (start) / supprimer (rm)rm).CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30ca0ec083d3 nginx:1.23 "/docker-entrypoint.…" 1 second ago Exited (0) Less than a second ago my-nginx
9ac1410fec7c nginx:1.23 "/docker-entrypoint.…" 2 hours ago Up 2 hours 80/tcp web
Lancer un conteneur
alpine, exécuteruname -a, puis le supprimer.
zsh: command not found: run
docker: 'docker rm' requires at least 1 argument
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
See 'docker rm --help' for more information
--rm peut être utilisée avec docker run pour supprimer automatiquement le conteneur après son arrêt.docker logs.-f permet de suivre les logs en temps réel.05fa0eb6fd301b7e1572ead0e83924c3872d422e55e177fe8194b33e78aa3e27
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2026/01/19 13:10:31 [notice] 1#1: using the "epoll" event method
2026/01/19 13:10:31 [notice] 1#1: nginx/1.23.4
2026/01/19 13:10:31 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6)
2026/01/19 13:10:31 [notice] 1#1: OS: Linux 6.17.12-300.fc43.x86_64
2026/01/19 13:10:31 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 524288:524288
2026/01/19 13:10:31 [notice] 1#1: start worker processes
2026/01/19 13:10:31 [notice] 1#1: start worker process 29
2026/01/19 13:10:31 [notice] 1#1: start worker process 30
2026/01/19 13:10:31 [notice] 1#1: start worker process 31
2026/01/19 13:10:31 [notice] 1#1: start worker process 32
2026/01/19 13:10:31 [notice] 1#1: start worker process 33
2026/01/19 13:10:31 [notice] 1#1: start worker process 34
2026/01/19 13:10:31 [notice] 1#1: start worker process 35
2026/01/19 13:10:31 [notice] 1#1: start worker process 36
2026/01/19 13:10:31 [notice] 1#1: start worker process 37
2026/01/19 13:10:31 [notice] 1#1: start worker process 38
2026/01/19 13:10:31 [notice] 1#1: start worker process 39
2026/01/19 13:10:31 [notice] 1#1: start worker process 40
2026/01/19 13:10:31 [notice] 1#1: start worker process 41
2026/01/19 13:10:31 [notice] 1#1: start worker process 42
2026/01/19 13:10:31 [notice] 1#1: start worker process 43
2026/01/19 13:10:31 [notice] 1#1: start worker process 44
2026/01/19 13:10:31 [notice] 1#1: start worker process 45
2026/01/19 13:10:31 [notice] 1#1: start worker process 46
2026/01/19 13:10:31 [notice] 1#1: start worker process 47
2026/01/19 13:10:31 [notice] 1#1: start worker process 48
2026/01/19 13:10:31 [notice] 1#1: start worker process 49
2026/01/19 13:10:31 [notice] 1#1: start worker process 50
docker exec permet d’exécuter des commandes dans un conteneur en cours d’exécution.docker stats affiche l’utilisation des ressources (CPU, mémoire, réseau, disques) des conteneurs en cours d’exécution.--no-stream affiche une seule fois les statistiques.docker network create.--network.Error response from daemon: network with name app-net already exists
docker: Error response from daemon: Conflict. The container name "/web" is already in use by container "9ac1410fec7cde6b9ee85cc7f153f01a29e92ce9c5aa9e92270a44901fdc7d36". You have to remove (or rename) that container to be able to reuse that name.
Run 'docker run --help' for more information
b8706dc1f3308aebd42efaed304d7fcd25d51cc80bdd563ce26d7176a0599779
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
100 615 100 615 0 0 680k 0 --:--:-- --:--:-- --:--:-- 600k
[
{
"Name": "app-net",
"Id": "07a59e9d4462b3ca6362df7e0436b9aa9b651e3143c21517c9c76b626d18751b",
"Created": "2026-01-19T11:08:35.751867093Z",
"Scope": "local",
"Driver": "bridge",
"EnableIPv4": true,
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.18.0.0/16",
"IPRange": "",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Options": {},
"Labels": {},
"Containers": {
"9ac1410fec7cde6b9ee85cc7f153f01a29e92ce9c5aa9e92270a44901fdc7d36": {
"Name": "web",
"EndpointID": "633661e6e8fda5f8b8161a1ccfedea4b3672ec7875b8f7811bf85b71cf306dd7",
"MacAddress": "fa:4e:15:91:bd:fa",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"b8706dc1f3308aebd42efaed304d7fcd25d51cc80bdd563ce26d7176a0599779": {
"Name": "db",
"EndpointID": "9226f81741135064d2c27e9a1299d5e481a3eea069ba70e4eaf68ce6284fd754",
"MacAddress": "8e:08:cf:81:69:df",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Status": {
"IPAM": {
"Subnets": {
"172.18.0.0/16": {
"IPsInUse": 5,
"DynamicIPsAvailable": 65531
}
}
}
}
}
]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
100 615 100 615 0 0 817k 0 --:--:-- --:--:-- --:--:-- 600k
Créer un réseau
mynet, lancer deux conteneursalpinenommésa1eta2sur ce réseau, puis vérifier qu’ils se ping par nom.
-p hôte:conteneur.-p 8080:80 mappe le port 8080 de l’hôte vers le port 80 du conteneur.curl ou un navigateur.http://localhost:8080 si Docker est natif.host.docker.internal comme nom d’hôte. % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 615 100 615 0 0 632k 0 --:--:-- --:--:-- --:--:-- 600k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
-v volume:chemin_dans_conteneur.pgdata
docker: Error response from daemon: Conflict. The container name "/db" is already in use by container "b8706dc1f3308aebd42efaed304d7fcd25d51cc80bdd563ce26d7176a0599779". You have to remove (or rename) that container to be able to reuse that name.
Run 'docker run --help' for more information
Hint: regarder la page officielle Postgres Docker Hub pour le chemin des données. (see https://hub.docker.com/_/postgres)
Exercice 3 (10 min)
Lancer un conteneur Postgres avec volume, créer une table, arrêter et relancer, puis vérifier que les données sont toujours présentes.
Limiter CPU / mémoire / PIDs
docker update.Total reclaimed space: 0B
Total reclaimed space: 0B
Deleted Volumes:
bf0826de7e362d8adb399bd6472ffca675d548dc5c740591578f486a6d087a49
Total reclaimed space: 88B
Éviter latest en production
Ne pas stocker de secrets dans l’environnement
--secret (ou mécanismes externes).Logs sur stdout/stderr
Objectif
Assembler une application simple avec :
nginx + postgres sur app-net
nginx expose un service web
postgres stocke les données dans un volume
Nettoyage final
E. Bruno - Conteneurs: Notions de base (Usage)