Search code examples
dockerdocker-swarmdocker-image

How to remove an image across all nodes in a Docker swarm?


On the local host, I can remove an image using either docker image rm or docker rmi.

What if my current host is a manager node in a Docker swarm and I wish to cascade this operation throughout the swarm?

When I first created the Docker service, the image was pulled down on each node in the swarm. Removing the service did not remove the image and all nodes retain a copy of the image.

It feels natural that if there's a way to "push" an image out to all the nodes then there should be an equally natural way to remove them too without having to SSH into every single machine :'( Plus, this is a real problem. Sooner or later the nodes are bound to have no more disk space!


Solution

  • AFAIK there is no such option as of now. Each node is responsible of its own cleanup. There is a command docker system prune -f that you can use to clear container data.

    But tagged images can be deleted using docker rmi only. See below issues

    https://github.com/moby/moby/issues/24079