Cleaning up Docker resources

1 min read
Note on

In good old days, we used to write scripts to cleanup stale Docker containers, images, volumes, etc. Docker Engine 1.25 provided a welcome change on this. Now, there’s a relatively straightforward way to cleanup unused resources using the following command.

sh
docker system prune

With this single command, you can remove all stopped containers, unused networks, dangling images, and build cache.

Even more importantly, prune is also available for other resource commands.

sh
docker container prune  # removes all stopped containers
docker image prune      # removes unused images
docker network prune    # removes all unused networks
docker volume prune     # removes all unused local volumes
docker builder prune    # removes build cache

There are also a couple of useful flags available:

You can read more about these commands in system, container, image, network, volume and builder references.

Share