People that work with Docker know it is easy to create a large number of containers. Occasionally you need to stop all running containers on your machine. This can be accomplished by using docker stop
together with docker ps
(using command substitution).
docker stop $(docker ps -q)
docker ps
is used to list all running containers. The -q
option will display only the container IDs. Usage of the docker ps
command can be seen below:
Usage: docker ps [OPTIONS]
List containers
Options:
-a, --all Show all containers (default shows just running)
-f, --filter value Filter output based on conditions provided (default [])
--format string Pretty-print containers using a Go template
--help Print usage
-n, --last int Show n last created containers (includes all states) (default -1)
-l, --latest Show the latest created container (includes all states)
--no-trunc Don't truncate output
-q, --quiet Only display numeric IDs
-s, --size Display total file sizes