docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete
Digest: sha256:56433a6be3fda188089fb548eae3d91df3ed0d6589f7c2656121b911198df065
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/
Ce qui se passe :
đ„ Docker cherche l'image localement
đ TĂ©lĂ©charge depuis Docker Hub si nĂ©cessaire
đïž CrĂ©e un conteneur
đ ExĂ©cute le conteneur
Si on relance la commande docker run hello-world, vous noterez que l'image n'est pas re-téléchargé.
Commande docker images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 1b44b5a3e06a 3 months ago 10.1kB
Commande docker ps liste l'ensemble des container actifs
stef@tuto01:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
On note qu'aucun containers n'apparait,l'option -a permet d'ajouter au listing les containers inactifs
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6d1e47b38472 hello-world "/hello" About a minute ago Exited (0) About a minute ago amazing_bose
7cf53b014be2 hello-world "/hello" 20 minutes ago Exited (0) 20 minutes ago affectionate_raman
**ID: ID du container
IMAGE: l'image utilisé par le docker
COMMAND: La commande ou script appeler au demarrage du conteners
CREATED: Date de création
STATUS: Etat du container
PORTS: Port exposé par le container
NAMES: Nom du container, si aucun nom est indiqué au moment de la création spécifié un nom aléatoire est généré
l'id ou le nom peuvent ĂȘtre indiffĂ©rement utilisĂ©s
La commande est docker rm nom_du_containe ou id_du_container
docker rm amazing_bose
amazing_bose
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7cf53b014be2 hello-world "/hello" 21 minutes ago Exited (0) 21 minutes ago affectionate_raman
docker rm 7cf53b014be2
7cf53b014be2
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Les containers sont créér a partir d'une image, la commande docker search permet de retrouver une image spécifique
docker search almalinux
NAME DESCRIPTION STARS OFFICIAL
almalinux The official build of AlmaLinux OS. 201 [OK]
almalinux/almalinux DEPRECATION NOTICE: This image is deprecated⊠9
almalinux/9-base AlmaLinux 9 Base container image 0
...
...
docker run -ti --name alma01 almalinux bash
Unable to find image 'almalinux:latest' locally
latest: Pulling from library/almalinux
d2ed363a5c15: Pull complete
Digest: sha256:375aa0df1af54a6ad8f4dec9ec3e0df16feec385c4fb761ac5c5ccdd829d0170
Status: Downloaded newer image for almalinux:latest
[root@1c7e82125b68 /]#
L'option -ti permet de lancer le container en mode interactf
L'option --name permet de nommer explicitement le container
Le dernier champs apres le nom de l'image force le container à executer la commande indiqué, bash dans l'exemple
Vous pouvez maintenant lancer des commande dans le shell indiqué
[root@1c7e82125b68 /]# ls
afs bin dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@1c7e82125b68 /]# cat /etc/redhat-release
AlmaLinux release 9.6 (Sage Margay)
[root@1c7e82125b68 /]# dnf update -y
Last metadata expiration check: 0:01:45 ago on Sun Nov 9 07:16:00 2025.
Dependencies resolved.
===================================================================================================================================================================================================================================
Package Architecture Version Repository Size
===================================================================================================================================================================================================================================
Upgrading:
glib2 x86_64 2.68.4-16.el9_6.3 baseos 2.6 M
glibc x86_64 2.34-168.el9_6.24 baseos 1.9 M
glibc-common x86_64 2.34-168.el9_6.24 baseos 293 k
glibc-minimal-langpack x86_64 2.34-168.el9_6.24 baseos 20 k
gnutls x86_64 3.8.3-6.el9_6.2 baseos 1.1 M
iputils x86_64 20210202-11.el9_6.3 baseos 167 k
systemd x86_64 252-51.el9_6.3.alma.2 baseos 4.0 M
systemd-libs x86_64 252-51.el9_6.3.alma.2 baseos 667 k
systemd-pam x86_64 252-51.el9_6.3.alma.2 baseos 274 k
systemd-rpm-macros noarch 252-51.el9_6.3.alma.2 baseos 62 k
vim-minimal x86_64 2:8.2.2637-22.el9_6.1 baseos 669 k
Transaction Summary
===================================================================================================================================================================================================================================
Upgrade 11 Packages
...
...
Upgraded:
glib2-2.68.4-16.el9_6.3.x86_64 glibc-2.34-168.el9_6.24.x86_64 glibc-common-2.34-168.el9_6.24.x86_64 glibc-minimal-langpack-2.34-168.el9_6.24.x86_64 gnutls-3.8.3-6.el9_6.2.x86_64
iputils-20210202-11.el9_6.3.x86_64 systemd-252-51.el9_6.3.alma.2.x86_64 systemd-libs-252-51.el9_6.3.alma.2.x86_64 systemd-pam-252-51.el9_6.3.alma.2.x86_64 systemd-rpm-macros-252-51.el9_6.3.alma.2.noarch
vim-minimal-2:8.2.2637-22.el9_6.1.x86_64
Complete!
[root@1c7e82125b68 /]# exit
exit
Vous noterez que vous ĂȘtes dans un OS Almalinux (type Redhat) sur un os de type Debian
Si on relance la mĂȘme commande:
docker run -ti --name alma01 almalinux bash
docker: Error response from daemon: Conflict. The container name "/alma01" is already in use by container "1c7e82125b68a230f51b0b8e309729a52ff90f9cf0dfe8f9d48f38fd97db0611". You have to remove (or rename) that container to be able to reuse that name.
Run 'docker run --help' for more information
Le container précedant, bien qu'inactif, étant toujours existant, docker indique un conflit de nommage.
Effacons le container
docker rm alma01
alma01
--hostname: Fixe le hostname du container
Relancons le mĂȘme container avec cette option
docker run -ti --name alma01 --hostname alma01 almalinux bash
[root@alma01 /]#
Relancer la commande dnf update -y dans le container, que remarquez vous ?
Puis éffacer la container
Schéma 4 : Cycle de vie d'un conteneur
Commandes du cycle :
docker create # Créé
docker start # Démarre
docker stop # ArrĂȘte
docker rm # Supprime
Commande: docker images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
almalinux latest 1e86a8eba5bf 2 months ago 189MB
hello-world latest 1b44b5a3e06a 3 months ago 10.1kB
Commande: docker rmi nom_image ou id_image
docker image prune -a
WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
Deleted Images:
untagged: hello-world:latest
untagged: hello-world@sha256:56433a6be3fda188089fb548eae3d91df3ed0d6589f7c2656121b911198df065
deleted: sha256:1b44b5a3e06a9aae883e7bf25e45c100be0bb81a0e01b32de604f3ac44711634
deleted: sha256:53d204b3dc5ddbc129df4ce71996b8168711e211274c785de5e0d4eb68ec3851
untagged: almalinux:latest
untagged: almalinux@sha256:375aa0df1af54a6ad8f4dec9ec3e0df16feec385c4fb761ac5c5ccdd829d0170
deleted: sha256:1e86a8eba5bf814057cadccc09b4304d4e029ed4adeea6cd2bf404fc907e4446
deleted: sha256:f9378cbae16e324dc83d5e393ccaa7be744f6b53f9ea51c259a6090948bf913a
Total reclaimed space: 188.7MB
docker create -ti --name alma01 --hostname alma01 almalinux bash
Unable to find image 'almalinux:latest' locally
latest: Pulling from library/almalinux
d2ed363a5c15: Pull complete
Digest: sha256:375aa0df1af54a6ad8f4dec9ec3e0df16feec385c4fb761ac5c5ccdd829d0170
Status: Downloaded newer image for almalinux:latest
90d3d94d202b64735c8093850da74b6320de39e6b978b8ca4cbcace8020b1010
Le container est bien créé mais n'est pas encore lancé.
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90d3d94d202b almalinux "bash" 7 seconds ago Created alma01
Demarrons le container:
docker start alma01
alma01
On note que nous n'avons pas la main sur le container mais qu'il est en cours d'execution
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90d3d94d202b almalinux "bash" 32 seconds ago Up 7 seconds alma01
On peut lancer des commandes dans le container via la commande docker exec
Note: on ajoute l'option -ti afin de pouvoir agir en mode interactif (-i) avec le terminal (-t)
docker exec -ti alma01 bash
[root@alma01 /]# exit
exit
Le container est toujours actif:
stef@tuto01:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90d3d94d202b almalinux "bash" About a minute ago Up 36 seconds alma01
Essayer d'effacer le container, que remarquez vous ?
Stoppez le container avec la commande docker stop alma01
Puis l'effacer avec la commande docker rm alma01
L'option -f permet de stopper puis effacer le container, exemple : docker rm -f alma01