Nathan Nguyen
Nathan Nguyen

Reputation: 61

How can I deploy docker swarm user docker stack with services by order

I have an issue about Docker Swarm.

I have tried to deploy my app with Docker Swarm Mode.

But I can not arrange my services start by order, although I was used depends_on (It’s recommended not support for docker stack deploy).

How can I deploy that with services start by order

Ex:

Service 1 starting

Service 2 wait for Service 1

Please help.

Upvotes: 6

Views: 2218

Answers (2)

Thomas Decaux
Thomas Decaux

Reputation: 22671

There is no orchestration system that recommend or support this feature.

So forgot about it because this is a very bad idea.

Application infrastructure (here the container) should not depend on the database health, but your application itself must depend on the database health.

You see the difference?

For instance, the application could display an error message "Not ready yet" or "This feature is disabled because elasticsearch is down" etc...

So even if this is possible to implement this pattern (aka "wait-for", with kubernetes, you can use initContainer to "wait" for another service up&ready), I strongly recommend to move this logic to your application.

Upvotes: 0

herm
herm

Reputation: 16315

This is not supported by Swarm.

Swarm is designed for high availability. When encountering problems (services or hosts fail) services will be restartet in the order they failed.

If you have clear dependencies between your services and they can't handle waiting for the other service to be available or reconnecting, your system won't work.

Your services should be written in a way that they can handle any service being redeployed at any time.

Upvotes: 11

Related Questions