Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: clean up all stopped containers except data-only containers

Tags:

docker

What is the Docker way to clean up all stopped Docker containers but retain data-only containers?

  • docker rm $(docker ps -qa -f status=exited) removes these too!

How to clean up the according images?

like image 336
Jens Piegsa Avatar asked Dec 15 '22 17:12

Jens Piegsa


1 Answers

In general there is no definitive way to distinguish data-only from other containers. If you wish them to survive your cleansing, you could probably design a certain name scheme and have more elaborate scripts that wouldn't remote containers with name, say, starting with data-.

like image 153
Mykola Gurov Avatar answered May 22 '23 17:05

Mykola Gurov