• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • All
  • About
Docker | Clear Docker Unused Objects
  1. Clear images cache
  2. Clear stopped containers
  3. Clear unused networks
  4. Clear unused local volumes
  5. Clear all Docker unused objects (images, containers, networks, local volumes)

  1. Clear images cache
    You can use the command docker image prune to remove all dangling and intermediate images:

    First, let's list existing images:

    By default intermediate images are hidden, you need to use the option -a (--all) to list all images:

    Remove dangling images:

    Check that dangling and intermediate images were deleted:

    It's also possible to use this command to remove dangling images:
  2. Clear stopped containers
    You can use the command docker container prune to remove all stopped containers:

    Let's start a container:

    Check the container (note that the container exited because it didn't run in foreground):

    Remove stopped containers:

    It's also possible to use this command to remove all containers with the status exited:
  3. Clear unused networks
    You can use the command docker network prune to remove all unused networks (not attached to a running container):

    Create a test network:

    Remove unused networks:
  4. Clear unused local volumes
    You can use the command docker volume prune to remove all unused local volumes (not attached to a running container):

    Create a test volume:

    Let's use the created volume:

    Let's check the data in the volume:

    Let's remove the unused volumes:

    You could also remove specific volumes using the command docker volume rm:
  5. Clear all Docker unused objects (images, containers, networks, local volumes)
    You can also use the command docker system prune to remove all unused objects. This will remove images cache, stopped containers, unused networks, and unused local volumes:

    Remove unused objects:
© 2025  mtitek