5

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

martin
  • 135
  • 5
  • 12

2 Answers2

8

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/

1

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?

invad0r
  • 908
  • 1
  • 7
  • 20