The current best practice is:
docker system prune
Note the output from this command prior to accepting the consequences:
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N]
In other words, continuing with this command is permanent. Keep in mind that best practice is to treat stopped containers as ephemeral i.e. you should be designing your work with Docker to not keep these stopped containers around. You may want to consider using the --rm
flag at runtime if you are not actively debugging your containers.
Make sure you read this answer, re: Volumes
You may also be interested in this answer, if docker system prune
does not work for you.