Premiers Pas

🔍 Les Essentiels de Docker

1

docker run hello-world

Testez votre installation en exécutant un conteneur Docker simple.

docker run hello-world

Ce que cela fait :

  • Télécharge l’image hello-world si elle n’est pas présente localement.

  • Crée un conteneur à partir de cette image.

  • Exécute un script affichant un message de bienvenue.

Exemple d'output :

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d211f485f2dd1dee407a80973c8f129f00d54604d2c90732e8e320e5038a0348
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
2

docker image pull alpine

Télécharge l’image alpine depuis Docker Hub.

docker image pull alpine

Explication :

  • alpine est une distribution Linux légère, parfaite pour des conteneurs minimalistes.

Exemple d'output :

Using default tag: latest
latest: Pulling from library/alpine
43c4264eed91: Pull complete
Digest: sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
3

docker image ls

Cette commande affiche toutes les images Docker disponibles localement sur votre machine.

docker image ls

Explication des colonnes :

  • REPOSITORY : Nom de l'image.

  • TAG : Version spécifique (ex : latest).

  • IMAGE ID : Identifiant unique de l'image.

  • CREATED : Date de création de l'image.

  • SIZE : Taille de l'image sur le disque.

Exemple d'output :

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
alpine        latest    91ef0af61f39   2 months ago    7.8MB
hello-world   latest    d2c94e258dcb   18 months ago   13.3kB

Ce que cela montre :

  • Deux images locales : alpine et hello-world.

  • L'image alpine est une distribution légère, idéale pour les tâches simples.

  • L'image hello-world est une image de test.

4

docker container run

La commande suivante permet d'exécuter un conteneur à partir d'une image et de lister son contenu :

docker container run alpine ls -l

Explication :

  • alpine : Image utilisée (légère et rapide).

  • ls -l : Commande exécutée à l'intérieur du conteneur pour afficher la liste des fichiers et répertoires avec des détails.


Exemple d'output :

total 56
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 bin
drwxr-xr-x    5 root     root           340 Nov  6 10:27 dev
drwxr-xr-x    1 root     root          4096 Nov  6 10:27 etc
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 home
drwxr-xr-x    6 root     root          4096 Sep  6 11:34 lib
drwxr-xr-x    5 root     root          4096 Sep  6 11:34 media
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 mnt
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 opt
dr-xr-xr-x  289 root     root             0 Nov  6 10:27 proc
drwx------    2 root     root          4096 Sep  6 11:34 root
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 run
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 sbin
drwxr-xr-x    2 root     root          4096 Sep  6 11:34 srv
dr-xr-xr-x   13 root     root             0 Nov  6 10:27 sys
drwxrwxrwt    2 root     root          4096 Sep  6 11:34 tmp
drwxr-xr-x    7 root     root          4096 Sep  6 11:34 usr
drwxr-xr-x   12 root     root          4096 Sep  6 11:34 var

🗂️ Description des répertoires

  • bin : Contient les commandes binaires de base.

  • dev : Fichiers spéciaux représentant les périphériques.

  • etc : Fichiers de configuration.

  • home : Répertoire personnel.

  • lib : Bibliothèques nécessaires pour les binaires.

  • media / mnt : Points de montage pour les systèmes de fichiers.

  • proc : Système de fichiers virtuel contenant des informations sur les processus en cours.

  • root : Répertoire personnel de l'utilisateur root.

  • tmp : Fichiers temporaires.

  • usr : Programmes utilisateur, bibliothèques et documentations.

  • var : Fichiers variables comme les logs et caches.


📦 Gestion des Conteneurs Docker

1

Lister les conteneurs

Listez tous les conteneurs, y compris ceux qui sont arrêtés :

docker container ls -a

Exemple d'output :

CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                       PORTS     NAMES
a8d99b4b89c2   hello-world   "/hello"                 7 minutes ago   Exited (0) 7 minutes ago               crazy_sanderson
2

Démarrer un conteneur arrêté

Relancez un conteneur à l’aide de son CONTAINER ID ou son nom :

docker start <container_id>
3

Interagir avec un conteneur actif

Ouvrez un terminal interactif dans un conteneur en cours d'exécution :

docker exec -it <container_id> /bin/sh
4

Arrêter un conteneur actif

Pour arrêter un conteneur en cours d'exécution :

docker stop <container_id>
5

Nettoyer le système Docker

Supprimez les conteneurs arrêtés, les images inutilisées et le cache :

docker system prune

Exemple d'output :

WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - unused build cache

Are you sure you want to continue? [y/N] y
Deleted Containers:
705047281d58549bafdce54aa26bff3172a091eaa9db2a047858af98eb737529
2d10505a0e998877814e12340c936c7d88c6002025ff86600193233f068015eb
8b7073d2f0ffd525a1157aae4844e072acbe86f022238262c2837186e8bf2664
28b2bd50fd5c1d0f1965324356df03fbcaab18f1fe83d943e5bf2b143c315098
349d98fcdeb2d220da1a3491f1fb6c7c0f31840b81a58c71b99ce179ca800058
e86891ebaae3bde6661646e89c704ff87478bbf5a9ad0dab7e8b60efd5f8e54b
b970c51940d1be2574761399910775271781dc5d75490fb8f76c4b955807dd3b
459736c5b03f858a5ee3a5defdbdf659d8b6a7cc3557c231dfd4ce5a1caff5e5
94a1303177b1a2eaa65f4e17cd32540d85f8b1802e392af6263dd013d65031ba
a8d99b4b89c226aeb0b1ecd31def23de562a61aa218dbcf4930e82cf7b37543c

Total reclaimed space: 142B

🌍 Déploiement d’un Serveur Web avec Nginx

1

Lancer Nginx

docker run -d -p 8080:80 nginx
2

Vérifier l'état des conteneurs

docker container ls
3

Répertoire du fichier web

Accédez au conteneur Nginx :

docker exec -ti <container_id> bash

Puis, accédez à :

cd /usr/share/nginx/html

⚙️ Terminologie Docker

🖼️ Images

Les images sont des systèmes de fichiers prêts à l'emploi. Vous pouvez en savoir plus avec :

docker image inspect <image_name>

📦 Conteneurs

Les conteneurs sont des instances exécutées d'images.

docker container run <image_name>

🛠️ Docker Daemon

Service qui exécute et gère Docker en arrière-plan.

📋 Client Docker

L'outil en ligne de commande pour interagir avec Docker.

🏪 Docker Hub

Registre public pour partager et télécharger des images Docker.

Last updated