Cheatsheet | Docker
Docker provides the ability to package and run an application in a loosely isolated environment called a container.
The isolation and security allows you to run many containers simultaneously on a given host. Containers are lightweight and contain everything needed to run the application, so you do not need to rely on what is currently installed on the host. You can easily share containers while you work, and be sure that everyone you share with gets the same container that works in the same way.
commandes générales
| start the docker daemon |
|
| help / manuel | docker --help |
| display system wide info | docker info |
gestionGestion de containers
runtime instance of an image
| démarrer un conteneur arrêté |
|
| redémarrer un conteneur |
|
| arrêter un conteneur |
|
| mettre en pause un conteneur |
|
| reprendre un conteneur |
|
| afficher les logs pour debug |
|
| details sur le conteneur démarré |
|
| ressource utilisé par le conteneur |
|
docker rm conteneur
supprimer tous les conteneurs stoppésdocker container prune
⚠ inclut ceux qui run
docker inspectrm <id>-f
$(docker inspect <id> | grep APP_COLOR-B1ps -A1aq)
docker run --name containerName imageName
run container & publiser its port(s) to the host
docker run -p <hostPort>:<container:port> <imageName>
docker run -d <imageName>docker rm <containerName>docker rm -f $(docker ps -aq)
docker exec -it <containerName> sh
| afficher les conteneurs démarrés | docker ps |
docker ps -adocker logs -f containerName
docker container ls -a -q --filter "ancestor=x"
possible d'ajouter d'autres filtres
docker container ls -a -q --filter "ancestor=x" --filter "status=exited"
detail d'un container
docker inspect <id>
docker inspect <id> | grep APP_COLOR
possible d'ajouter -B1 -A1 après le grep pour ajouter une ligne avant et après le résultat pour plus de clarté et trouver le résultat facilement
imageGestion d'images
exec une image docker run imageName
( -d to detach —name to name it)
build an image from a dockerfile
docker build -t <imageName> .
build an image from a dockerfile without the cache
docker build -t <imageName> . -no-cache
docker
imagesTrouver
docker rmi <imageName>docker image prune
docker run --rm x cat /etc/os-release (exemple x = python:3.6)
supprimer 1 image
docker rmi imageName
delete all images (if a running cont is using image, conflict = need to remove cont)
docker rmi -f $(docker images -aq)
supprimer toutes les images non utilisées
docker image inspectprune
hub
service provided bypar Docker topour findtrouver andet sharepartager des images
log in docker login -u <username>
publish docker push <username>/<imageName>
search docker search <imageName>
get docker pull <imageName>
nettoyageNettoyage
Les commandes prune ne suppriment jamais les conteneurs en cours d’exécution, seulement ceux arrêtés ou les objets « non utilisés ».
Utiliser sans -f pour voir les warning mais besoin de l'ajouter dans les scripts car non interractifs.
|
Supprimer tous les conteneurs arrêtés |
|
|
Supprimer les images « dangling » |
|
|
⚠ Supprimer toutes les images non utilisées par un conteneur ⚠ |
|
|
Volumes inutilisés (non attachés à un conteneur)
|
|
|
Réseaux non utilisés |
|
|
Nettoyage global (conteneurs arrêtés, images inutilisées, réseaux inutilisés, build cache) |
|