Docker

Différents affichages avec docker en CLI

Les containers, leur image, le port, la taille sur 2 lignes

docker ps -a -q --format 'table {{ .Names }}\t{{ .Status }}\t{{ .Size }}\n{{ .ID }}\t{{ .Image }}{{ if .Ports }}{{ with $p := split .Ports ", " }}\t{{ len $p }} port(s) on {{ end }}{{- .Networks }}{{ else }}\tNo Ports on {{ .Networks }}{{end}}\n'
NAMES          STATUS    SIZE
CONTAINER ID   IMAGE     5 port(s) on NETWORKS

pihole         Up 21 hours (healthy)   25.5MB (virtual 327MB)
a88a9053be02   pihole/pihole:latest    4 port(s) on pihole_default

nextcloud_app_1   Up 21 hours        6.3kB (virtual 1.14GB)
124466fed567      nextcloud:27.0.1   1 port(s) on nextcloud_default

glpi_mariadb   Up 21 hours     2B (virtual 403MB)
737cc3bf26ae   mariadb:10.11   1 port(s) on glpi_default

nextcloud_db_1   Up 21 hours     2B (virtual 403MB)
febad01cc316     mariadb:10.11   1 port(s) on nextcloud_default

nginx          Up 21 hours                        25.5kB (virtual 148MB)
b722ae3d6ff4   lscr.io/linuxserver/nginx:latest   2 port(s) on nginx_default

glpi_glpi      Up 21 hours   1.57MB (virtual 283MB)
9f5255c550b8   diouxx/glpi   2 port(s) on glpi_default

yacht_app_1    Up 21 hours                                 12.7MB (virtual 425MB)
53a04b972ad2   selfhostedpro/yacht:latest-2022-06-03--21   1 port(s) on yacht_default

Lister les images inutilisées

RUNNINGS_IMAGES=$(docker ps --format {{.Image}})
docker images --format "table {{.ID}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" \
| grep -v "$RUNNINGS_IMAGES"
unset RUNNINGS_IMAGES

Exemple de rendu :

root@localhost:/# RUNNINGS_IMAGES=$(docker ps --format {{.Image}}); docker images --format "table {{.ID}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" | grep -v "$RUNNINGS_IMAGES" ; unset RUNNINGS_IMAGES
IMAGE ID       SIZE      REPOSITORY:TAG
cb09058f6eed   418MB     synapse:mainline
a8bb53036fd3   93.2MB    otel/opentelemetry-collector:latest
b9559acf35ef   60.3MB    jaegertracing/all-in-one:latest
b50ee6079167   223MB     registry.gitlab.com/mb-saces/synatainer:latest
2f20774a9bec   724MB     ttrss:latest
e148e14f6f5b   243MB     halfshot/matrix-appservice-discord:latest