docker¶
see also:
docker (compose) formatting¶
just display the name, service, state, and status of containers in a docker compose project:
and for docker ps:
exec as other user (e.G. root)¶
with docker exec (where ac0 is the container id):
or with docker compose (znc is the container name):
docker logs¶
the default json log can become pretty large if you're running a container for weeks. there are multiple options for logging, to simply use syslog globally for all containers:
create or edit /etc/docker/daemon.json:
or like this:
changes in the daemon.json only apply to new containers, not existing.
docker cleanup¶
get rid of exited containers:
get rid of unused images:
docker (compose) resource monitoring¶
quickly get resource usage, such as cpu and memory, for each container in a docker compose project:
get the total usage of the whole project combined:
docker stats --no-stream --format "table {{.CPUPerc}}\t{{.MemUsage}}" $(docker compose ps -q) | awk 'NR>1 {cpu+=$1; mem+=$2} END {print "Total CPU: " cpu "%, Total Memory: " mem}'
backup / export docker volumes¶
backup a single docker volume¶
backup the volume named foobar:
docker run --rm -v "foobar:/data" -v "$(pwd):/backup" alpine tar czf /backup/foobar_$(date +%F).tar.gz -C /data .
restore:
docker run --rm -v "foobar:/data" -v "$(pwd):/backup" alpine tar xzf /backup/foobar_2025-10-25.tar.gz -C /data
backup all docker volumes¶
docker volume ls -q | xargs -I {} docker run --rm -v "{}:/data" -v "$(pwd):/backup" alpine tar czf /backup/{}_$(date +%F).tar.gz -C /data .
backup docker volumes using a filter¶
of all volumes starting with the name foo, useful for docker compose projects:
docker volume ls -q -f name=^foo | xargs -I {} docker run --rm -v "{}:/data" -v "$(pwd):/backup" alpine tar czf /backup/{}_$(date +%F).tar.gz -C /data .
docker and ipv6¶
enable ipv6 with docker compose¶
create a new network to your compose.yaml and add this network to your container(s), example:
services:
pihole:
image: pihole/pihole:latest
networks:
- leela-network
ports:
- 53:53/tcp
- 53:53/udp
environment:
TZ: Europe/Paris
volumes:
- pihole-etc:/etc/pihole
- pihole-dnsmasq:/etc/dnsmasq.d
restart: unless-stopped
networks:
leela-network:
enable_ipv6: true
the above enables ipv6 and ipv4 for your container
more docker ipv6 stuff¶
this is for your /etc/docker/daemon.json file. it might not exist.