Skip to main content

Que vous soyez DevOps ou Simple Ops ou développeur d’applications, vous aurez besoin de supprimer des containers Docker à un moment ou un autre. Cela s’avère nécéssaire lors d’une phase de déploiement. Il m’est arrivé de cloner des containers pour endiguer la montée en charge des requetes.

docker rm $(docker ps -a -q) removes/deletes all stopped containers

Stop all running containers:docker stop $(docker ps -a -q)

Delete all stopped containers: docker rm $(docker ps -a -q)

The Docker CLI command to stop one or more containers is: docker stop, while the command to delete one or more containers is docker rm.

You can use these to stop and delete multiple containers by passing them a list of the containers you want to remove. The shell syntax $() returns the results of whatever is executed within the brackets. So you can create your list of containers within this to be passed to the stop and rm commands.

Here is a breakdown of docker ps -a -q

  • docker ps list containers
  • -a the option to list all containers, even stopped ones. Without this, it defaults to only listing running containers
  • -q the quiet option to provide only container numeric IDs, rather than a whole table of information about containers