Maintain Docker

Get basic information:

docker system info


To troubleshoot docker compose commands, add the --verbose option.

Reference: Overview of docker compose CLI

Review log files

Run, replacing CONTAINER:

docker compose logs -f -t CONTAINER

Container logs are cleared when containers are restarted or recreated.

To read historic container logs, replacing CONTAINER:

less /var/log/docker-custom/CONTAINER.log

Open a shell

Open a Bash shell, for example:

docker compose run --rm --name my-app-shell static bash

Open a Python shell, for example:

docker compose run --rm --name my-app-shell cron python shell

Our Python projects follow a LOG_LEVEL environment variable, which you can set with -e LOG_LEVEL=DEBUG, for example.

Check project usage

Show containers’ status:

docker compose ps

Show containers’ processes:

docker compose top

Check system-wide usage

Check drive usage:

docker system df

List containers, images, networks and volumes:

docker container ls -a
docker image ls -a
docker network ls
docker volume ls

Inspect a volume, replacing VOLUME:

docker volume inspect VOLUME

List a volume’s data, replacing VOLUME:

ls /var/lib/docker/volumes/VOLUME/_data/*

Prune objects

List dangling objects:

docker image ls --filter dangling=true
docker volume ls --filter dangling=true

Prune unused objects:

docker system prune

Remove unused images in addition to dangling ones:

docker system prune -a

Reference: Prune unused Docker objects