Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete volumes in swarm cluster?

I have a swarm cluster with one manager and another normal node , when I create a swarm service I am creating with mount type ,mount source and mount target . It creates the volume with the same name in both manger and node and starts the container and my service is up.

When I release the service the volume created along with the service was not deleted, this is still fine.

The problem I am facing is when I delete the volume with the same endpoint it's only deleting the volume in swarm manager, the volume created in the node while creating the service still exists.

I want the manager to delete all the volumes which is created along with the swarm service. Is there a way ??

like image 993
Vishnu Ranganathan Avatar asked Nov 24 '16 18:11

Vishnu Ranganathan


2 Answers

After so much of analysis here is the theory.

if you are instructing swarm to create the service with volume, Swarm is only performing actions on creating the services inside the cluster i.e on the multiple nodes yes when you send the volume details yes it does creates the volume as well but while releasing the service it fails to check in the worker nodes for existence of volume while releasing Its the bug in docker

I have raised the bug in docker for it.

As of now there is no other way than manually releasing the volume from worker nodes after releasing the swarm service .

like image 77
Vishnu Ranganathan Avatar answered Oct 18 '22 20:10

Vishnu Ranganathan


As far as I know a volume is only created on nodes where a container is created. Is it possible that your service fails to start on one node, ends up on the other and somehow swarm doesn't clean up? If thats the case write an issue in github.

Update (from comments):

According to the docker service create documentation:

A named volume is a mechanism for decoupling persistent data needed by your container from the image used to create the container and from the host machine. Named volumes are created and managed by Docker, and a named volume persists even when no container is currently using it. Data in named volumes can be shared between a container and the host machine, as well as between multiple containers. Docker uses a volume driver to create, manage, and mount volumes. You can back up or restore volumes using Docker commands.

So if you are using named volumes the correct answer would be why are they removed on the manager and where they ever created there?

like image 37
herm Avatar answered Oct 18 '22 18:10

herm