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 |
| list images available | docker images |
| delete one 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) |
| run image ( -d to detach —name to name it) | docker run imageName |
| stop container | docker stop contName |
| remove all stopped containers | docker container prune |
| remove all containers | docker rm -f $(docker ps -aq) |
| delete image not used without a name | docker image prune |
| pull one image | docker pull imageName |
| delete all image cont network cache | docker system prune -af --volumes |
gestion 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 |
|
- detail d'un container
docker inspect <id>- possible de filtrer
docker inspect <id> | grep APP_COLOR - possible d'ajouter
-B1 -A1après le grep pour ajouter une ligne avant et après le résultat pour plus de clarté et trouver le résultat facilement
- possible de filtrer
- create & run container from image with a custom name
docker run --name containerName imageName - run container & publiser its port(s) to the host
docker run -p <hostPort>:<container:port> <imageName> - run in background
docker run -d <imageName> - remove a container
- a stopped one
docker rm <containerName> - all of them containers, including running ones
docker rm -f $(docker ps -aq)
- a stopped one
- open shell in running container
docker exec -it <containerName> sh
| afficher les conteneurs démarrés | docker ps |
| afficher tous les conteneurs | docker ps -a (a pour all) |
| afficher les logs pour debug |
|
| afficher l'ID des conteneurs utilisant une image X (not running) |
possible d'ajouter d'autres filtres
|
|
|
image
- 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 - list local images
docker images - delete an image
docker rmi <imageName>→ rmi for remove image - remove all unused images
docker image prune - find base OS for x image
docker run --rm x cat /etc/os-release(exemple x = python:3.6) - find image size
docker image inspect <imageNAme> --format '{{.Size}}'
hub
service provided by Docker to find and share images
log in docker login -u <username>
publish docker push <username>/<imageName>
search docker search <imageName>
get docker pull <imageName>
nettoyage
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) |
|