Skip to content

Instantly share code, notes, and snippets.

@Sp0ne
Last active October 25, 2023 12:29
Show Gist options
  • Save Sp0ne/79cd049d05c4108d743d677b4e919ea8 to your computer and use it in GitHub Desktop.
Save Sp0ne/79cd049d05c4108d743d677b4e919ea8 to your computer and use it in GitHub Desktop.
Docker cheat sheet : utils command memo

Docker Memo

docs.docker.com

Analyze how much space Docker is using

➜ docker system df
➜ docker system df -v

Exemple:

➜ docker system df

TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          110       43        27.76GB   15.49GB (55%)
Containers      61        32        4.747GB   364.8MB (7%)
Local Volumes   1009      8         71.95GB   67.8GB (94%)
Build Cache     0         0         0B        0B

Prune everything

➜ docker system prune

Clean Up Everything

➜ docker system prune -a
➜ docker system prune --volumes

-a includes unused and dangling containers
--volumes Volumes are not pruned by default, you must specify

Clean up unused and dangling images

➜ docker image prune
➜ docker image prune -a
➜ docker image prune -a --filter "until=24h"

-a clean up dangling images only

Clean up unused volume

➜ docker volume prune

Clean up container

➜ docker container prune
➜ docker container prune --filter "until=24h"

Format Docker ps

➜ docker ps -s --format "table {{.ID}} \t {{.Names}} \t {{.Status}}"

Exemple:

➜ docker ps -s --format "table {{.ID}} \t {{.Names}} \t {{.Status}}"

CONTAINER ID     NAMES                STATUS
1445fa8911a7     container-php        Up 39 seconds
a27893c870a9     container-nodejs     Up 35 seconds (healthy)
0a61b789a16c     container-maria      Up 35 seconds
408a894f85da     container-pma        Up 39 seconds

➜ docker logs --tail 50 --follow --timestamps [NAME]
➜ docker stats [NAME]
➜ docker inspect [NAME]
➜ docker top [NAME] (processus)

Access to current container

docker exec -it [NAME] bash
OR
docker-compose -f ./docker-compose.yml -f ./docker-compose.main.yml -p [PROJECT] exec --user www-data [NAME] bash

Create a new clone container

docker-compose -f ./docker-compose.yml -f ./docker-compose.main.yml -p [PROJECT] run --user www-data [NAME] bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment