Docker pruning

I went to create a container and got an error that it already existed.

docker: Error response from daemon: Conflict. The container name "/sql2017u2" is already in use by container "7f8319be7b727d6294cbf9d298afc8de6da783ceb33bfeaa136d147890d1bdbe". You have to remove (or rename) that container to be able to reuse that name.

Hmm, I thought I had removed it. To see all your Docker containers running or not, run this at the command line:

docker ps -a


I discovered I had a bunch of them hanging out there:

Thankfully, there’s an easy way to remove all the containers that are not running:

docker container prune

It will warn you and ask you if you are sure you want to remove all stopped containers:

Type y and hit enter.

A list of deleted container IDs and total space reclaimed is displayed.

Then run docker ps -a again, and you will see your stopped containers are gone.

You can also use prune to remove images, volumes, and networks.

  • docker image prune – removes images without at least one container associated with them (don’t do this if you want to reuse the image again, but just aren’t currently using it otherwise it has to be downloaded again)
  • docker volume prune – removes volumes if they aren’t used by at least one container, but be careful because then the data on them is deleted forever
  • docker network prune – remove networks if they aren’t used by at least one container

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.