A WIP collection of docker commands for maintaining services running on subdomains and limited disk space while I experiment. I still don’t know what docker really is.

container cleanup

Source: https://docs.docker.com/engine/manage-resources/pruning/

clean up all images that don’t have at least one container associated with them

docker image prune -a

clean up all stopped docker containers

docker container prune

clean up all anonymous docker volumes not used by at least one container

docker volume prune

clean up all custom docker networks not used by at least one container

docker network prune

all of the above (just use this command)

docker system prune

information

break down container usage (-v for more info)

docker system df [-v]

another way to show disk usage

docker ps --size

show running containers (-a flag shows all running containers)

docker ps [-a]

another way to show containers

docker container ls

logs

start with last 10 log entries and follow log output (think tail -f)

docker compose logs -f -n 10

script to update docker containers

# ~/.local/bin/dockerpull
 
#!/bin/bash
dockerdir="/home/user/docker"                 
for dir in $(ls $dockerdir); do
	cd "$dockerdir/$dir"
	docker compose pull && docker compose up -d
done

crontab file

  • must be run as root
# every Sunday at 12am run dockerpull script
0 0 * * 7 /home/user/.local/bin/dockerpull