Skip to content

Docker: Cleanup

6 Docker commands: Cleanup. Click a command to see what each part does.

Index
6 items
Click a command to see what each part does.

Cleanup6

  • docker system dfHow much space Docker uses

    What each part does

    1. docker system dfspace used by images, containers, volumes and build cache, plus how much is reclaimable
  • docker ps -q | xargs -r docker stopStop all running containersCaution

    What each part does

    1. docker ps -qIDs of running containers
    2. |pipe them to xargs
    3. xargs -rpass them as arguments; -r: don't run if the list is empty
    4. docker stopstop each one gracefully (SIGTERM, then SIGKILL after 10s)
  • docker ps -aq --filter status=exited | xargs -r docker rmRemove all exited containersCaution

    What each part does

    1. -aqall containers, IDs only
    2. --filter status=exitedonly exited ones
    3. xargs -r docker rmremove them

    Tip Same result: docker container prune

  • docker system prune -f --filter "until=24h"Remove unused data older than a dayCaution

    What each part does

    1. docker system pruneremove stopped containers, unused networks, dangling images and build cache
    2. -f--force: no confirmation prompt
    3. --filter "until=24h"only things older than 24 hours
  • docker system prune -a --volumesRemove everything unused, including volumesDestructive

    What each part does

    1. -a--all: also every image not used by a container (not just dangling)
    2. --volumesalso unused volumes: this deletes data
  • docker builder prune -af --filter "until=24h"Remove build cache onlyCaution

    What each part does

    1. docker builder pruneremove BuildKit build cache (image prune does not touch it)
    2. -aall cache, not only dangling
    3. -fno prompt
    4. --filter "until=24h"keep the last day of cache

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…