Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 627
E235 Avatar asked Mar 28 '18 15:03

E235


4 Answers

The same solution exists in services:

docker service rm $(docker service ls -q)
like image 51
Bret Fisher Avatar answered Oct 08 '22 16:10

Bret Fisher


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
like image 32
Carlos Alberto P. Moura Jr. Avatar answered Oct 08 '22 16:10

Carlos Alberto P. Moura Jr.


Found a way:

docker service ls | grep -v '^ID' | awk '{print $1}' | xargs docker service rm
like image 23
E235 Avatar answered Oct 08 '22 15:10

E235


This is a one way to do it.

docker service rm $(docker service ls --format "{{.ID}}")
like image 20
Rulindil Avatar answered Oct 08 '22 15:10

Rulindil