How can I prevent a Docker Container from being used while another container in the same service is trying?

I want multiple containers to be included together. I am assuming I have a service and I want to enable 5 replicas.

Then they should proceed as follows:

container 1 is running ==> container 1 is running and healthy ==> container 2 is running ==> container 2 is running and healthy ==> container 3 is running ==> container 3 is running and healthy ==> container 4 is starting ==> container 4 running and healthy ==> container 5 is running ==> container 5 is running and healthy.

I checked HEALTHCHECK but I don't know for sure if it helps in this case

thank

+3


source to share


1 answer


You can add another application container to act as a coordinator.

It is related to this question .

My idea is to have a shared Redis that you share. That way, every new container that starts a request for that lock that is in shared Redis, and when the lock is acquired, the container finishes starting, then release the lock.



https://redis.io/topics/distlock

Distributed locks are a very useful primitive in many environments where different processes must operate on shared resources in a mutually exclusive way.

+1


source







All Articles