Utilisation des conteneurs Docker

Présentation de Docker

Tim Sangster

Software Engineer @ DataCamp

Affichage des conteneurs

repl@host:/# docker ps
CONTAINER ID   IMAGE    .. CREATED         STATUS         ...  NAMES
3b87ec116cb6   postgres    2 seconds ago   Up 1 second    ...  adoring_germain
8a7830bbc787   postgres    3 seconds ago   Up 2 seconds   ...  exciting_heisenberg
fefdf1687b39   postgres    3 seconds ago   Up 2 seconds   ...  vigilant_swanson
b70d549d4611   postgres    4 seconds ago   Up 3 seconds   ...  nostalgic_matsumoto
a66c71c54b92   postgres    4 seconds ago   Up 4 seconds   ...  lucid_matsumoto
8d4f412adc3f   postgres    6 seconds ago   Up 5 seconds   ...  fervent_ramanujan
fd0b3b2a843e   postgres    7 seconds ago   Up 6 seconds   ...  cool_dijkstra
0d1951db81c4   postgres    8 seconds ago   Up 7 seconds   ...  happy_sammet
...
Présentation de Docker

Conteneurs nommés

docker run --name <container-name> <image-name>
repl@host:/# docker run --name db_pipeline_v1 postgres
repl@host:/# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED  
43aa37614330   postgres   "docker-entrypoint.s…"   About a minute ago
STATUS              PORTS      NAMES
Up About a minute   5432/tcp   db_pipeline_v1
docker stop <container-name>
repl@host:/# docker stop db_pipeline_v1
Présentation de Docker

Filtrage des conteneurs en cours d'exécution

docker ps -f "name=<container-name>"
repl@host:/# docker ps -f "name=db_pipeline_v1"
CONTAINER ID   IMAGE      COMMAND                  CREATED  
43aa37614330   postgres   "docker-entrypoint.s…"   About a minute ago
STATUS              PORTS      NAMES
Up About a minute   5432/tcp   db_pipeline_v1
Présentation de Docker

Registres des conteneurs

docker logs <container-id>
repl@host:/# docker logs 43aa37614330
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".

PostgreSQL init process complete; ready for start up.

2022-10-24 12:10:40.318 UTC [1] LOG:  database system is ready to accept connect..
Présentation de Docker

Journaux en direct

docker logs -f <container-id>
repl@host:/# docker logs -f 43aa37614330
PostgreSQL init process complete; ready for start up.

2022-10-24 12:10:40.309 UTC [1] LOG:  starting PostgreSQL 14.5 (Debian 14.5-1.pg..
2022-10-24 12:10:40.309 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port ..
2022-10-24 12:10:40.309 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-10-24 12:10:40.311 UTC [1] LOG:  listening on Unix socket "/var/run/postgre..
2022-10-24 12:10:40.315 UTC [62] LOG:  database system was shut down at 2022-10-..
2022-10-24 12:10:40.318 UTC [1] LOG:  database system is ready to accept connect..
Présentation de Docker

Nettoyage

docker container rm <container-id>
repl@host:/# docker stop 43aa37614330
43aa37614330
repl@host:/# docker container rm 43aa37614330
43aa37614330
Présentation de Docker

Résumé des nouvelles commandes

Utilisation Commande
Démarrer le conteneur avec un nom docker run --name <container-name> <image-name>
Filtrer le conteneur en cours d'exécution par nom docker ps -f "name=<container-name>"
Consulter les journaux existants pour le conteneur docker logs <container-id>
Consulter les journaux en direct pour le conteneur docker logs -f <container-id>
Quitter l'affichage du journal en direct du conteneur CTRL+C
Retirer le conteneur immobilisé docker container rm <container-id>
Présentation de Docker

Passons à la pratique !

Présentation de Docker

Preparing Video For Download...