Wiki-Tech.io/Conteneurisation/Docker/Commandes.html

286 lignes
7.9 KiB
HTML

<!--
title: Commandes utiles
description: Petit mémo avec toutes les commandes utilisées au quotidien avec Docker.
published: true
date: 2021-05-24T10:34:16.861Z
tags:
editor: ckeditor
dateCreated: 2021-05-24T10:34:15.369Z
-->
<h1>Docker</h1>
<h2>Monitoring</h2>
<figure class="table">
<table>
<thead>
<tr>
<th>Commande</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>docker info</code></td>
<td>Afficher les informations générales de votre Docker</td>
</tr>
<tr>
<td><code>docker ps (-a)</code></td>
<td>Afficher les containers en cours de fonctionnement (<code>-a</code> = afficher aussi les containers arrêtés)</td>
</tr>
<tr>
<td><code>docker stats --all</code></td>
<td>Affiche les statistiques des conteneurs</td>
</tr>
<tr>
<td><code>docker image ls</code></td>
<td>Afficher les images téléchargées et construites sur votre machine</td>
</tr>
<tr>
<td><code>docker network ls</code></td>
<td>Afficher les réseaux créer sur votre machine</td>
</tr>
<tr>
<td><code>docker inspect &lt;container&gt;</code></td>
<td>Inspecter la configuration d'un conteneur</td>
</tr>
<tr>
<td><code>docker logs (--tail) &lt;container&gt;</code></td>
<td>Visualiser les logs d'un conteneur (<code>--tail</code> = afficher les logs en live)</td>
</tr>
<tr>
<td><code>docker exec -it &lt;container&gt; bash</code></td>
<td>&nbsp;Exécuter des commandes dans un conteneur actif</td>
</tr>
</tbody>
</table>
</figure>
<p>&nbsp;</p>
<h2>Démarrer un container</h2>
<pre><code class="language-plaintext">docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]</code></pre>
<p>&nbsp;</p>
<figure class="table">
<table>
<thead>
<tr>
<th>Option</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>-i</code></td>
<td>Garder STDIN ouvert, même si pas attaché</td>
</tr>
<tr>
<td><code>-t</code></td>
<td>Allouer un pseudo-terminal</td>
</tr>
<tr>
<td><code>-p</code></td>
<td>Configurer le port</td>
</tr>
<tr>
<td><code>-v&nbsp;</code></td>
<td>Lier un dossier sur le serveur au conteneur</td>
</tr>
<tr>
<td><code>-c</code></td>
<td>Créer un partage</td>
</tr>
<tr>
<td><code>-d</code></td>
<td>Activer le mode daemon. Le conteneur sera actif et en tâche de fond</td>
</tr>
<tr>
<td><code>-e&nbsp;</code></td>
<td>Forcer Docker a utiliser un driver exec spécifique</td>
</tr>
<tr>
<td><code>--name</code></td>
<td>Identifier un conteneur par un nom au lieu d’un ID</td>
</tr>
<tr>
<td><code>--dns</code></td>
<td>Définir un DNS personnalisé</td>
</tr>
<tr>
<td><code>--net="&lt;mode&gt;"</code></td>
<td>Définir le mode réseau entre “Bridge”, “none”, “container:” et “host”</td>
</tr>
<tr>
<td><code>--network</code></td>
<td>Connecter le container à un réseau existant</td>
</tr>
<tr>
<td><code>--add-host</code></td>
<td>Modifier le contenu du fichier “hosts” en y ajoutant les valeurs spécifiées</td>
</tr>
<tr>
<td><code>--link</code></td>
<td>Ajouter un lien vers un autre conteneur</td>
</tr>
</tbody>
</table>
</figure>
<p>&nbsp;</p>
<h2>Gestion des containers</h2>
<figure class="table">
<table>
<thead>
<tr>
<th>Commande</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>docker run &lt;image&gt; &lt;options&gt;</code></td>
<td>Démarrer un container à partir d'une image avec les options configurées</td>
</tr>
<tr>
<td><code>docker ps</code></td>
<td>Afficher tous les containers en cours d'exécutions</td>
</tr>
<tr>
<td><code>docker ps -a</code></td>
<td>Afficher tous les containers</td>
</tr>
<tr>
<td><code>docker stop &lt;container&gt;</code></td>
<td>Arrêter un container</td>
</tr>
<tr>
<td><code>docker stop $(docker ps -aq)</code></td>
<td>Arrêter tous les containers</td>
</tr>
<tr>
<td><code>docker restart &lt;container&gt;</code></td>
<td>Redémarrer un container</td>
</tr>
<tr>
<td><code>docker kill &lt;container&gt;</code></td>
<td>Envoyer la commande kill à un container</td>
</tr>
<tr>
<td><code>docker rm &lt;container&gt;</code></td>
<td>Supprimer un container</td>
</tr>
<tr>
<td><code>docker rm $(docker ps -aq)</code></td>
<td>Supprimer tous les containers</td>
</tr>
</tbody>
</table>
</figure>
<p>&nbsp;</p>
<h2>Gestion des images</h2>
<figure class="table">
<table>
<thead>
<tr>
<th>Commande</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>docker search &lt;mot_clé&gt;</code></td>
<td>Rechercher une image</td>
</tr>
<tr>
<td><code>docker pull &lt;image:tag&gt;</code></td>
<td>Télécharger l'image depuis le repo</td>
</tr>
<tr>
<td><code>docker push &lt;dossier/image&gt;</code></td>
<td>Envoyer l'image au repo</td>
</tr>
<tr>
<td><code>docker image</code></td>
<td>Afficher les images téléchargées sur la machine</td>
</tr>
<tr>
<td><code>docker rmi &lt;image&gt;</code></td>
<td>Supprimer une image</td>
</tr>
<tr>
<td><code>docker rmi $(docker image -q)</code></td>
<td>Supprimer toutes les images</td>
</tr>
<tr>
<td><code>docker build &lt;options&gt;</code></td>
<td>Créer une image (voir <a href="/Docker/Image">/Docker/Image</a>)</td>
</tr>
</tbody>
</table>
</figure>
<p>&nbsp;</p>
<h2>Gestion des réseaux</h2>
<figure class="table">
<table>
<thead>
<tr>
<th>Commande</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>docker network ls</code></td>
<td>Afficher les réseaux existants sur la machine</td>
</tr>
<tr>
<td><code>docker network create --driver &lt;driver_type&gt; &lt;réseau&gt;</code></td>
<td>Créer un réseau avec un driver spécifique &nbsp;(voir <a href="/Docker/Réseau">/Docker/Réseau</a>)</td>
</tr>
<tr>
<td><code>docker network inspect &lt;réseau&gt;</code></td>
<td>Afficher les informations d'un réseau</td>
</tr>
<tr>
<td><code>docker network rm &lt;réseau&gt;</code></td>
<td>Supprimer un réseau</td>
</tr>
</tbody>
</table>
</figure>
<p>&nbsp;</p>
<hr>
<h1>Docker-Compose</h1>
<figure class="table">
<table>
<thead>
<tr>
<th>Commande</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>docker-compose up</code></td>
<td>Lancer la stack</td>
</tr>
<tr>
<td><code>docker-compose up -d</code></td>
<td>Lancer la stack en daemon</td>
</tr>
<tr>
<td><code>docker-compose pull</code></td>
<td>Télécharger les images de la stack</td>
</tr>
<tr>
<td><code>docker-compose stop</code></td>
<td>Arrêter les containers</td>
</tr>
<tr>
<td><code>docker-compose down</code></td>
<td>Supprimer les containers</td>
</tr>
<tr>
<td><code>docker-compose logs</code></td>
<td>Afficher les logs des containers</td>
</tr>
</tbody>
</table>
</figure>