If containers have names with same prefix, for example: test-service-1, test-service-2, test-something-more, then it's possible to stop them all at once:
$ docker ps -q --filter name=CONTAINER_NAME_PREFIX* \
xargs docker stop
If you'll add -a to docker ps, you can also change xargs docker stop to xargs docker container rm to remove all containers at once.
You can also stop and remove containers in one command:
$ docker ps -q --filter name=CONTAINER_NAME_PREFIX* | \
xargs docker stop | xargs docker container rm
Top comments (0)