TIL that you need to remove your stopped Docker containers from time to time (and how to do it)

1 minute read Published:

If you ever developed with Docker, you have to acknowledge that it is great!

Ok… you have to wrap your brain around an additional layer with all those caveats we know and love (volumes, path in- and outside of containers, …), but it lets you bundle all your dependencies at build time and then ship an image that will run in every docker-compatible runtime!

When you develop with Docker and do a lot of start/stop/build actions you will inevitably clutter your Docker Host with many unused containers.

Here is how to get rid of them:

  1. list all containers (running and stopped altogether) docker ps -a

  2. if there are too many of them (they are always too many!) run docker rm $(docker ps -a -q)

  3. the same trick applies to images (you maybe have to redownload some images after removing them)

    • list images: docker images
    • remove them: docker rmi $(docker images -a -q)