E235
E235

Reputation: 13440

How to remove all services in Docker Swarm

I want to remove all services I created in a Swarm:
enter image description here

To remove all the containers I used:

docker rm -f $(docker ps -a -q)

Is there a way to remove all the service with one line ?

I don't have a stack:
enter image description here
so docker stack rm STACK_NAME won't work.

Upvotes: 16

Views: 23338

Answers (5)

Lee
Lee

Reputation: 31040

For anyone looking to remove a subset of services, say with a given name, use a filter:

docker service rm $(docker service ls -f name=your_service_name -q)

Upvotes: 1

PasanNadeera
PasanNadeera

Reputation: 141

This is a one way to do it.

docker service rm $(docker service ls --format "{{.ID}}")

Upvotes: 2

You can just remore the stack

docker stack rm nameofstack

With this, all services will be removed.

To clean all volumes, containers, images and networks you can use:

docker system prune -a -f

Upvotes: 10

Bret Fisher
Bret Fisher

Reputation: 8596

The same solution exists in services:

docker service rm $(docker service ls -q)

Upvotes: 47

E235
E235

Reputation: 13440

Found a way:

docker service ls | grep -v '^ID' | awk '{print $1}' | xargs docker service rm

Upvotes: 1

Related Questions