martin
martin

Reputation: 155

Docker Swarm: How to remove stopped containers

i am currently learning docker and have set up a swarm with one manager and one cluster.

i run a stack with 2 replicas..everything is fine. when a container fails to run swarm will stop it and recreate it. thats awesome but the stopped containers wont get removed. is there a way to remove the stopped / unused containers automatically ?

Docker Swarm unused containers

Upvotes: 6

Views: 7407

Answers (2)

leandrosantos89
leandrosantos89

Reputation: 142

There's a option --task-history-limit.

So you can do something like this:

docker swarm update --task-history-limit=1

Take a look at the cli docs: https://docs.docker.com/engine/reference/commandline/swarm_update/

Upvotes: 10

invad0r
invad0r

Reputation: 926

Docker swarm doesn't provide a way of removing stopped containers automatically.

You will have to run docker system prune --all manually on your node or create a cron-job which does that for your.

see also: How to delete unused docker images in swarm?

Upvotes: 1

Related Questions