🕒 : 3 h maximum

On va découvrir l’usage de DOCKER , ici sur la version ubuntu 26.04 (en boite)

Container , pour enfermer un applicatif.

Docker est une plateforme open-source de virtualisation légère au niveau du système d’exploitation. Elle permet d’empaqueter une application et toutes ses dépendances (bibliothèques, fichiers de configuration, variables d’environnement) dans un objet standardisé appelé conteneur, qui s’exécute de manière isolée sur le noyau Linux hôte.

Cours à lire avant de commencer : Docker


Prérequis :

Machine linux de type Debian (ubuntu 26.04 au lycée kernel 7)

But:

Installer une ubuntu 26.04 pour découvrir la puissance de Docker.

Voir les commandes de base de docker.

charger des images / créer / sauvegarder

Administrer une machine linux ubuntu 26.04

Répertoire de travail:

~/Works/Docker/TP0

1- Mise en place de Docker et chargement de l’image ubuntu 26.04

installation de docker sur votre machine

Sur votre machine vérifier que docker existe :

docker --version
Docker version 26.1.5+dfsg1, build a72d7cd

si aucune installation alors il faut installer Docker !

installation de docker

sudo apt update
sudo apt install docker.io util-linux-extra -y

Ensuite il faut vous ajouter dans le groupe docker

Pour éviter de passer en root pour utiliser docker , il faut vous placer dans le groupe docker (plus simple à administrer)

sudo adduser etudiant docker

# verifier !! le résultat 
sssd:x:110:
lpadmin:x:111:etudiant
fwupd-refresh:x:982:
saned:x:112:
geoclue:x:113:
pipewire:x:981:
gnome-remote-desktop:x:980:
polkitd:x:979:
rtkit:x:978:
colord:x:977:
gnome-initial-setup:x:976:
gdm:x:975:
lxd:x:114:
etudiant:x:1000:
gamemode:x:974:
vboxusers:x:972:
docker:x:115:etudiant
etudiant@ordi:~/Works$ 
#validation du group sans rebooter (par contre valable au reboot)
etudiant@ordi:~$ groups  # on y est pas encore
etudiant adm cdrom sudo dip plugdev users lpadmin
etudiant@ordi:~$ newgrp docker #on se met dans le group
etudiant@ordi:~$ groups  # on y est ! et c'est mieux   , etudiant pourra utiliser docker !
docker adm cdrom sudo dip plugdev users lpadmin etudiant
etudiant@ordi:~$ 

Vérification du fonctionnement de docker !

un petit docker de test existe et on va réaliser notre hello-world !

etudiant@ordi:~$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
4f55086f7dd0: Pull complete 
d5e71e642bf5: Download complete 
Digest: sha256:5dd0d3e6e255913fc30f90b9f2b1d359cc2cbdb48090cc4b65f1676e203243cc
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
etudiant@ordi:~$ docker run hello-world

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/

etudiant@ordi:~$ 

Si ça fonctionne , on peut continuer!

etudiant@ordi:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                          PORTS     NAMES
72dd5b039537   hello-world    "/hello"      2 minutes ago    Exited (0) About a minute ago             vigorous_zhukovsky

notre premier docker ! hello-world

on efface ce docker ! il a fait son job ! chez moi c’est vigorous_zhukovsky vous surement un autre nom !

etudiant@ordi:~$ docker rm vigorous_zhukovsky 
vigorous_zhukovsky
etudiant@ordi:~$ 

2- Installation d’une image ubuntu 26.04

docker pull ubuntu:26.04
# un reboot de la machine host est préférable 
etudiant@ordi:~$ cd Works/
etudiant@ordi:~/Works$ ls
Docker
etudiant@ordi:~/Works$ cd Docker/
etudiant@ordi:~/Works/Docker$ ls
etudiant@ordi:~/Works/Docker$ docker --version
Docker version 29.1.3, build 29.1.3-0ubuntu4.1
etudiant@ordi:~/Works/Docker$ docker pull ubuntu:26.04
26.04: Pulling from library/ubuntu
f3db1cd94078: Pull complete 
06e9d71331fb: Pull complete 
f79afc4bbefe: Download complete 
Digest: sha256:2260313b31c8c011cd2eebe728008efac1b3982be73eb71348ea2648d2c0e09b
Status: Downloaded newer image for ubuntu:26.04
docker.io/library/ubuntu:26.04
etudiant@ordi:~/Works/Docker$ 

3- Effacer l’image (rmi) et remettre !

etudiant@ordi:~/Works/Docker$ docker rmi ubuntu:26.04 
Untagged: ubuntu:26.04
Deleted: sha256:2260313b31c8c011cd2eebe728008efac1b3982be73eb71348ea2648d2c0e09b
etudiant@ordi:~/Works/Docker$ docker image ls
                                                                                     i Info →   U  In Use
IMAGE   ID             DISK USAGE   CONTENT SIZE   EXTRA
etudiant@ordi:~/Works/Docker$ 

Refaire l’étape 2 pour remettre l’image sur votre machine !

etudiant@ordi:~/Works/Docker$ docker pull ubuntu:26.04
26.04: Pulling from library/ubuntu
f3db1cd94078: Pull complete 
06e9d71331fb: Pull complete 
f79afc4bbefe: Download complete 
Digest: sha256:2260313b31c8c011cd2eebe728008efac1b3982be73eb71348ea2648d2c0e09b
Status: Downloaded newer image for ubuntu:26.04
docker.io/library/ubuntu:26.04
etudiant@ordi:~/Works/Docker$ docker image ls
                                                                                     i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB        
etudiant@ordi:~/Works/Docker$ 

4- liste des images (ici une seule) sur notre disque !

etudiant@ordi:~/Works/Docker$ docker image ls
                                                            i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB        
etudiant@ordi:~/Works/Docker$ 

on constate ici que ça consomme 160MB (Méga Bytes) Méga Octets! sur notre disque (ce qui est petit par rapport à une image virtuelle comme virtual box , mais ça n’est pas pareil ! )

5- Lancement de l’image ubuntu:26.04

docker run -it ubuntu:26.04

les options :

  • -i : intéractive
  • -t : tty (terminal)
etudiant@ordi:~/Works/Docker/TP0$ docker run -it ubuntu:26.04
root@ef7a1faa91ce:/# 

nous voila dans notre machine dans un Docker !

quelques manipulations pour comprendre ce qu’il c’est passé !

ici nous sommes root dans le terminal ! on a les pleins pouvoirs

Nous sommes dans une machine docker ubuntu 26.04 , il existe une liste non exhaustive de système linux !

root@ef7a1faa91ce:/# uname -a
Linux ef7a1faa91ce 7.0.0-30-generic #30-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 31 18:22:54 UTC 2026 x86_64 GNU/Linux
root@ef7a1faa91ce:/# 

on voit ici qu’on est sur un noyau (kernel) 7.0.0.-30 vous c’est surement mis à jour depuis 26/08/26 !


root@ef7a1faa91ce:/# cat /etc/os-release 
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
root@ef7a1faa91ce:/# 

on voit bien qu’on est sur une ubuntu 26.04 ! (mais pas votre machine hôte (host) ! votre docker) ici la machine hôte partage le noyau !

6- quitter et revenir !

On va réaliser un fichier dans le répertoire de travail de root: vi n’est pas encore installé ! , ici on va utiliser cat pour faire notre fichier bonjour contenant bonjour le monde en ASCII

root@ef7a1faa91ce:/# pwd 
/
root@ef7a1faa91ce:/# cd
root@ef7a1faa91ce:~# pwd
/root
root@ef7a1faa91ce:~# vi bonjour.txt
bash: vi: command not found
root@ef7a1faa91ce:~# cat > bonjour.txt
Bonjour le monde ! #ctrl d , pour quitter l'edition !
root@ef7a1faa91ce:~# ls
bonjour.txt
root@ef7a1faa91ce:~# cat bonjour.txt 
Bonjour le monde ! #ctrl d , pour quitter l'edition !
root@ef7a1faa91ce:~# 
on sort !
root@ef7a1faa91ce:~# exit

on est juste sorti du docker ! (la machine tourne toujours )

etudiant@ordi:~/Works/Docker/TP0$ docker ps 
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS                      PORTS     NAMES
ef7a1faa91ce   ubuntu:26.04   "/bin/bash"   15 hours ago   Exited (0) 19 seconds ago             hopeful_bose
etudiant@ordi:~/Works/Docker/TP0$ 
on rentre !
etudiant@ordi:~/Works/Docker/TP0$ docker start -ai ef7a1faa91ce
root@ef7a1faa91ce:/#
root@ef7a1faa91ce:/# cat /root/bonjour.txt 
Bonjour le monde ! #ctrl d , pour quitter l'edition !
root@ef7a1faa91ce:/# exit ou ctrl d (aussi) 

on peut utiliser le nom ici hopeful_bose

etudiant@ordi:~/Works/Docker/TP0$ docker start -ai hopeful_bose 
root@ef7a1faa91ce:/# cat /root/bonjour.txt 
Bonjour le monde ! #ctrl d , pour quitter l'edition !
root@ef7a1faa91ce:/# 
options : -ai   comme attach interactive
on ressort !!

on peut utiliser , ctrl d (exit) , mais aussi ctrl p et ctrl q

La machine est toujours la en fonction !!! Dans son docker !!épatant non ? , si vous éteignez , a votre reconnexion elle sera toujours la ! C’est la puissance de docker !

Tester de rebooter votre machine et vérifier votre Docker et ce fichier bonjour.txt!

7- On va réaliser la chose interdite !

Dans un terminal à coté de votre machine ubuntu 26.04 dans son docker , nous allons vérifier l’image et le docker qui tourne !

On dispose de l’image: on va le vérifier avec la commande docker image ls

etudiant@ordi:~$ docker image ls
                                                                                                            i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB    U   
etudiant@ordi:~$ 

image disponible sur votre machine ici ubuntu:26.04

etudiant@ordi:~$ docker ps
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS        PORTS     NAMES
ef7a1faa91ce   ubuntu:26.04   "/bin/bash"   15 hours ago   Up 15 hours             hopeful_bose
etudiant@ordi:~$ docker ps -a  # -a option pour all
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS        PORTS     NAMES
ef7a1faa91ce   ubuntu:26.04   "/bin/bash"   15 hours ago   Up 15 hours             hopeful_bose
etudiant@ordi:~$ 

Docker donne un nom à votre machine … par défaut , des petits noms ici hopeful_bose .. il en a pleins d’autres ! vous n’avez surement pas le même nom pour votre machine !

La commande interdite rm /* -rf en tant que root !!

Votre professeur ou d’autres vous on interdit cette commande et pour cause ! c’est toujours vrai ! la machine hôte doit rester comme neuve ! et on va utiliser un docker de la ubuntu 26.04 pour bien réaliser la gravité de la commande en root !

attention toujours interdite 🙂 sur votre machine d’apprentissage (hôte), car cette commande va effacer tout les fichiers de votre machine ! il faut juste faire cela dans un docker ! qui va protéger votre machine hôte !

ici la commande on va la taper dans le container (Docker) et juste détruire le container ! pas la machine hôte !!!

root@ef7a1faa91ce:/#rm /* -rf #ligne de la mort !
.......
.......
rm: cannot remove '/sys/module/drm/parameters/panic_screen': Read-only file system
rm: cannot remove '/sys/module/drm/parameters/edid_firmware': Read-only file system
rm: cannot remove '/sys/module/drm/parameters/edid_fixup': Read-only file system
rm: cannot remove '/sys/module/drm/parameters/timestamp_precision_usec': Read-only file system
rm: cannot remove '/sys/module/drm/parameters/debug': Read-only file system
rm: cannot remove '/sys/module/drm/parameters/vblankoffdelay': Read-only file system
root@ef7a1faa91ce:/# ls
bash: ls: command not found
root@ef7a1faa91ce:/# 
root@ef7a1faa91ce:/# exit
exit
etudiant@ordi:~$ .. ouf ici c'est sauf !

ls command not found !!! , chercher le fichier bonjour.txt !! on est pas dans la m …. non ! c’est juste notre docker notre fichier bonjour.txt qui est perdu !! OUFF

Oh notre machine est toujours la ! 🙂

etudiant@ordi:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED        STATUS                            PORTS     NAMES
ef7a1faa91ce   ubuntu:26.04   "/bin/bash"   15 hours ago   Exited (127) About a minute ago             hopeful_bose
etudiant@ordi:~$ 

on y retourne ?

etudiant@ordi:~$ docker start -ai hopeful_bose 
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: exec: "/bin/bash": stat /bin/bash: no such file or directory
etudiant@ordi:~$ 

on a juste tout cassé !! pour ceux qui avait besoin de le faire c’est fait !! plus rien n’est accessible , voila comment détruire une machine Linux !! Etre root ! comme le dit l’oncle BEN « De grands pouvoirs impliquent de grandes responsabilités »

c’est une base de l’informatique moderne ! root à tout pouvoirs

8- Tu casses, tu répares 🙂

on va définitivement supprimer la machine ! (un coup de balais)

etudiant@ordi:~$ docker rm hopeful_bose
hopeful_bose
etudiant@ordi:~$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~$ 

on va ensuite refaire un docker , on va en profiter pour lui coller un nom à nous cette fois ci.

docker run -it --name mon-ubuntu ubuntu:26.04

Dans un autre terminal vérifier que tout rentre en ordre !

etudiant@ordi:~$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS          PORTS     NAMES
3ffbecea7d57   ubuntu:26.04   "/bin/bash"   36 seconds ago   Up 35 seconds             mon-ubuntu

dans le terminal précédent :

etudiant@ordi:~$ docker run -it --name mon-ubuntu ubuntu:26.04
root@3ffbecea7d57:/# cat /root/bonjour.txt 
cat: /root/bonjour.txt: No such file or directory
root@3ffbecea7d57:/# 

il ne faut pas rêver 🙂 !! à vous de refaire le fichier bonjour.txt au bon endroit !

9- mise à jour de ma machine

attention surement diffèrent pour vous , ce sont juste des exemples :

apt update # mise à jour des listes sur la machine par rapport au dépôt .

root@3ffbecea7d57:/# apt update 
Get:1 http://archive.ubuntu.com/ubuntu resolute InRelease [136 kB]
Get:2 http://archive.ubuntu.com/ubuntu resolute-updates InRelease [137 kB]       
Get:3 http://archive.ubuntu.com/ubuntu resolute-backports InRelease [137 kB]
Get:4 http://security.ubuntu.com/ubuntu resolute-security InRelease [137 kB]
Get:5 http://archive.ubuntu.com/ubuntu resolute/universe amd64 Packages [20.1 MB]
Get:6 http://security.ubuntu.com/ubuntu resolute-security/restricted amd64 Packages [444 kB]
Get:7 http://security.ubuntu.com/ubuntu resolute-security/multiverse amd64 Packages [11.2 kB]
Get:8 http://security.ubuntu.com/ubuntu resolute-security/main amd64 Packages [520 kB]
Get:9 http://security.ubuntu.com/ubuntu resolute-security/universe amd64 Packages [196 kB] 
Get:10 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages [1874 kB]             
Get:11 http://archive.ubuntu.com/ubuntu resolute/multiverse amd64 Packages [352 kB]
Get:12 http://archive.ubuntu.com/ubuntu resolute/restricted amd64 Packages [189 kB]
Get:13 http://archive.ubuntu.com/ubuntu resolute-updates/restricted amd64 Packages [456 kB]
Get:14 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 Packages [676 kB]
Get:15 http://archive.ubuntu.com/ubuntu resolute-updates/universe amd64 Packages [317 kB]
Get:16 http://archive.ubuntu.com/ubuntu resolute-updates/multiverse amd64 Packages [14.3 kB]
Get:17 http://archive.ubuntu.com/ubuntu resolute-backports/universe amd64 Packages [3306 B]
Fetched 25.7 MB in 4s (7130 kB/s)                     
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@3ffbecea7d57:/# 

apt upgrade -y # mise à jour possible -y pour répondre toujours oui (yes) au questions possibles … gagne du temps

Upgrading:                      
  base-files  libssl3t64  openssl-provider-legacy

Summary:
  Upgrading: 3, Installing: 0, Removing: 0, Not Upgrading: 0
  Download size: 2477 kB
  Space needed: 2048 B / 17.1 GB available

Get:1 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 base-files amd64 14ubuntu6.2 [74.9 kB]
Get:2 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 openssl-provider-legacy amd64 3.5.5-1ubuntu3.4 [39.7 kB]
Get:3 http://archive.ubuntu.com/ubuntu resolute-updates/main amd64 libssl3t64 amd64 3.5.5-1ubuntu3.4 [2363 kB]
Fetched 2477 kB in 0s (5452 kB/s)  
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 79, <STDIN> line 3.)
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 entries checked: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.40.1 /usr/local/share/perl/5.40.1 /usr/lib/x86_64-linux-gnu/perl5/5.40 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl-base /usr/lib/x86_64-linux-gnu/perl/5.40 /usr/share/perl/5.40 /usr/local/lib/site_perl) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 8, <STDIN> line 3.)
debconf: falling back to frontend: Teletype
(Reading database ... 7724 files and directories currently installed.)
Preparing to unpack .../base-files_14ubuntu6.2_amd64.deb ...
Unpacking base-files (14ubuntu6.2) over (14ubuntu6.1) ...
Setting up base-files (14ubuntu6.2) ...
Installing new version of config file /etc/issue ...
Installing new version of config file /etc/issue.net ...
Installing new version of config file /etc/lsb-release ...
(Reading database ... 7724 files and directories currently installed.)
Preparing to unpack .../openssl-provider-legacy_3.5.5-1ubuntu3.4_amd64.deb ...
Unpacking openssl-provider-legacy (3.5.5-1ubuntu3.4) over (3.5.5-1ubuntu3.3) ...
Setting up openssl-provider-legacy (3.5.5-1ubuntu3.4) ...
(Reading database ... 7724 files and directories currently installed.)
Preparing to unpack .../libssl3t64_3.5.5-1ubuntu3.4_amd64.deb ...
Unpacking libssl3t64:amd64 (3.5.5-1ubuntu3.4) over (3.5.5-1ubuntu3.3) ...
Setting up libssl3t64:amd64 (3.5.5-1ubuntu3.4) ...
Processing triggers for libc-bin (2.43-2ubuntu2.3) ...
root@3ffbecea7d57:/# 

au passage bien mettre à jour ,est un réflexe évident en cyber sécurité.

10- on va installer vi (vim) qui nous manque

root@3ffbecea7d57:/# apt install vim -y

malgré le -y il faudra peut être répondre aux questions !

root@3ffbecea7d57:/# type vi
vi is /usr/bin/vi
root@3ffbecea7d57:/# type vim
vim is /usr/bin/vim
root@3ffbecea7d57:/# 

voila on dispose de vi !

root@3ffbecea7d57:/# ls /bin/vi -l
lrwxrwxrwx 1 root root 20 Aug 18 20:55 /bin/vi -> /etc/alternatives/vi
root@3ffbecea7d57:/# ls /etc/alternatives/vi -l
lrwxrwxrwx 1 root root 18 Aug 18 20:55 /etc/alternatives/vi -> /usr/bin/vim.basic
root@3ffbecea7d57:/# ls -l /usr/bin/vim.basic
-rwxr-xr-x 1 root root 4571880 Aug 18 20:55 /usr/bin/vim.basic
root@3ffbecea7d57:/# 

donner les explications à ces lignes !

dans la commande ls -l on voit des lrwxrwxrwx , le l est un lien !

explications :
  • /bin/vi (le chemin que tu tapes quand tu écris vi) n’est pas un vrai programme. C’est un lien symbolique (raccourci) vers un fichier de configuration.
  • /etc/alternatives/vi : C’est le dossier « aiguilleur » de Debian/Ubuntu. Il ne contient pas le vrai programme non plus, mais il décide quel éditeur sera lancé par défaut quand tu tapes vi.
  • /usr/bin/vim.basic : C’est le vrai binaire, le programme exécutable lui-même (qui pèse 4,5 Mo).

👉 En clair : Quand tu tapes vi, Linux suit le fil d’Ariane : il arrive au vrai programme vim.basic. C’est pour ça que tu te retrouves avec Vim, même si tu as tapé vi.

11- on va sauvegarder mon-ubuntu

on va créer une image de mon-ubuntu avec mon fichier bonjour.txt et vi !

etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                      PORTS     NAMES
3ffbecea7d57   ubuntu:26.04   "/bin/bash"   57 minutes ago   Exited (0) 26 seconds ago             mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker commit mon-ubuntu mon-ubuntu-avec-bonjour:v1
sha256:96acaa200f96fcf3291d8a1441a44e223238611d4c319916649c5040e9402f80
etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED          STATUS                      PORTS     NAMES
3ffbecea7d57   ubuntu:26.04   "/bin/bash"   57 minutes ago   Exited (0) 50 seconds ago             mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~/Works/Docker/TP0$ docker image ls
                                                                                                                                                                                               i Info →   U  In Use
IMAGE                        ID             DISK USAGE   CONTENT SIZE   EXTRA
hello-world:latest           5dd0d3e6e255       25.9kB         9.49kB        
mon-ubuntu-avec-bonjour:v1   96acaa200f96        350MB         99.5MB        
ubuntu:26.04                 2260313b31c8        160MB         45.3MB    U   
etudiant@ordi:~/Works/Docker/TP0$ 

docker images

etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE                        ID             DISK USAGE   CONTENT SIZE   EXTRA       
mon-ubuntu-avec-bonjour:v1   96acaa200f96        350MB         99.5MB        
ubuntu:26.04                 2260313b31c8        160MB         45.3MB    U   
etudiant@ordi:~/Works/Docker/TP0$ 

on va tester notre image

etudiant@ordi:~/Works/Docker/TP0$ docker run -it --name test-sauvegarde mon-ubuntu-avec-bonjour:v1
root@7fc37b249f89:/# cat /root/bonjour.txt 
Bonjour le monde 
root@7fc37b249f89:/# vi /root/bonjour.txt 
root@7fc37b249f89:/# exit

et on vérifie les docker en fonctionnement !

etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE                        COMMAND       CREATED              STATUS                      PORTS     NAMES
7fc37b249f89   mon-ubuntu-avec-bonjour:v1   "/bin/bash"   About a minute ago   Exited (0) 28 seconds ago             test-sauvegarde
3ffbecea7d57   ubuntu:26.04                 "/bin/bash"   About an hour ago    Exited (0) 7 minutes ago              mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ 

sauvegarde au format tar

etudiant@ordi:~/Works/Docker/TP0$ docker save -o sauvegarde-mon-ubuntu.tar mon-ubuntu-avec-bonjour:v1
etudiant@ordi:~/Works/Docker/TP0$ ls -l
total 97176
-rw------- 1 etudiant etudiant 99503616 Aug 26 10:47 sauvegarde-mon-ubuntu.tar
etudiant@ordi:~/Works/Docker/TP0$ 

chargement de l’image à partir du fichier tar

docker load -i sauvegarde-mon-ubuntu.tar

on va effacer et remettre

etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE                        COMMAND       CREATED             STATUS                      PORTS     NAMES
7fc37b249f89   mon-ubuntu-avec-bonjour:v1   "/bin/bash"   11 minutes ago      Exited (0) 10 minutes ago             test-sauvegarde
3ffbecea7d57   ubuntu:26.04                 "/bin/bash"   About an hour ago   Exited (0) 17 minutes ago             mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker rm test-sauvegarde 
test-sauvegarde
etudiant@ordi:~/Works/Docker/TP0$ docker rmi mon-ubuntu-avec-bonjour:v1 
Untagged: mon-ubuntu-avec-bonjour:v1
Deleted: sha256:96acaa200f96fcf3291d8a1441a44e223238611d4c319916649c5040e9402f80
etudiant@ordi:~/Works/Docker/TP0$ 

c’est clean!

etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED             STATUS                      PORTS     NAMES
3ffbecea7d57   ubuntu:26.04   "/bin/bash"   About an hour ago   Exited (0) 18 minutes ago             mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB    U   
etudiant@ordi:~/Works/Docker/TP0$ 

on va aller plus loin , comme dans c’est du propre

etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE          COMMAND       CREATED             STATUS                      PORTS     NAMES
3ffbecea7d57   ubuntu:26.04   "/bin/bash"   About an hour ago   Exited (0) 18 minutes ago             mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB    U   

etudiant@ordi:~/Works/Docker/TP0$ docker rm mon-ubuntu 
mon-ubuntu
etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE          ID             DISK USAGE   CONTENT SIZE   EXTRA
ubuntu:26.04   2260313b31c8        160MB         45.3MB        
etudiant@ordi:~/Works/Docker/TP0$ docker rmi ubuntu:26.04 
Untagged: ubuntu:26.04
Deleted: sha256:2260313b31c8c011cd2eebe728008efac1b3982be73eb71348ea2648d2c0e09b
etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE   ID             DISK USAGE   CONTENT SIZE   EXTRA
etudiant@ordi:~/Works/Docker/TP0$ 

voila ! c’est propre ! plus d’image plus de docker qui tourne !

etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE   ID             DISK USAGE   CONTENT SIZE   EXTRA
etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~/Works/Docker/TP0$ docker image ls
                                                                                                                                                                                               i Info →   U  In Use
IMAGE   ID             DISK USAGE   CONTENT SIZE   EXTRA
etudiant@ordi:~/Works/Docker/TP0$ 

On va utiliser notre sauvegarde !

etudiant@ordi:~/Works/Docker/TP0$ docker load -i sauvegarde-mon-ubuntu.tar
Loaded image: mon-ubuntu-avec-bonjour:v1
etudiant@ordi:~/Works/Docker/TP0$ docker images
                                                                                                                                                                                               i Info →   U  In Use
IMAGE                        ID             DISK USAGE   CONTENT SIZE   EXTRA
mon-ubuntu-avec-bonjour:v1   96acaa200f96        350MB         99.5MB        
etudiant@ordi:~/Works/Docker/TP0$ 

et on y va

etudiant@ordi:~/Works/Docker/TP0$ docker run -it mon-ubuntu-avec-bonjour:v1 
root@54ce826db162:/# 
root@54ce826db162:/# cat /root/bonjour.txt 
Bonjour le monde 

et on y retrouve vi

profitons pour regarder le contenu du fichier /etc/passwd

un utilisateur ubuntu existe,

Donner le répertoire ou il est hébergé ubuntu sur cette machine (docker)

Administration de la machine

regarder le fichier shadow

y a t’il un mot de passe pour root ?

y a t’il un mot de passe pour ubuntu ?

mettre un mot de passe à ubuntu , on lui mettra ubuntu

connecter vous en tant que ubuntu

root@54ce826db162:/# passwd ubuntu 
New password: 
Retype new password: 
passwd: password updated successfully
root@54ce826db162:/# vi /etc/shadow
root@54ce826db162:/# su - ubuntu
ubuntu@54ce826db162:~$ ls
ubuntu@54ce826db162:~$ pwd
/home/ubuntu
ubuntu@54ce826db162:~$ cd /root
-bash: cd: /root: Permission denied
ubuntu@54ce826db162:~$ 

pourquoi Permisson denied ?

le nom de la machine , contenu dans le fichier /etc/hostname

root@54ce826db162:/etc# cat hostname 
54ce826db162

on aura beau le modifier !! ça ne sera pris en compte qu’avec un reboot et la il faut juste le dire au démarrage du docker !

Donc on efface la machine !

etudiant@ordi:~/Works/Docker/TP0$ docker rm happy_wescoff 
happy_wescoff
etudiant@ordi:~/Works/Docker/TP0$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
etudiant@ordi:~/Works/Docker/TP0$ 
etudiant@ordi:~/Works/Docker/TP0$ docker run -it -h mon_serveur mon-ubuntu-avec-bonjour:v1 
root@mon_serveur:/# 
etudiant@ordi:~/Works/Docker/TP0$ docker run -it -h mon_serveur mon-ubuntu-avec-bonjour:v1
root@mon_serveur:/# cat /etc/hostname
mon_serveur
root@mon_serveur:/#

je deviens ubuntu

root@mon_serveur:/# su - ubuntu
ubuntu@mon_serveur:~$ pwd
/home/ubuntu
ubuntu@mon_serveur:~$ 

Exercices final

Exercice 1

créer un compte avec votre prénom et mot de passe ubuntu , faire une sauvegarde de la machine machine.tar

Exercice 2

Récupérer l’archive docker suivante sauvegarde mon_ubuntu.tar

lire cette image

Aide si besoin
bruno@debian13:~/Works/Docker/ubuntu2604$ docker load -i sauvegarde-mon-ubuntu.tar 
3cb6b8ba924b: Loading layer  57.92MB/57.92MB
Loaded image: mon-ubuntu-avec-bonjour:v1
bruno@debian13:~/Works/Docker/ubuntu2604$ docker images
REPOSITORY                TAG             IMAGE ID       CREATED         SIZE
mon-ubuntu-avec-bonjour   v1              352fa7e5eda9   22 hours ago    225MB

lancer cette image avec un hostname dorian

Aide si besoin
bruno@debian13:~/Works/Docker/ubuntu2604$ docker run -it -h dorian mon-ubuntu-avec-bonjour:v1
root@dorian:/#   

vérifier le fichier bonjour.txt , et que vi est accessible.