Containers

How do you remove old, non running, containers?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  1. To remove one or more Docker images use the docker container rm command followed by the ID of the containers you want to remove.
  2. The docker system prune command will remove all stopped containers, all dangling images, and all unused networks
  3. docker rm $(docker ps -a -q) - This command will delete all stopped containers. The command docker ps -a -q will return all existing container IDs and pass them to the rm command which will delete them. Any running containers will not be deleted.