How to deploy Kong to docker swarm?
As there is no answer here I will leave some things that I learned recently even if it's not related to Kong. This question seems more related to container startup order than to Kong itself.
The depends_on option is ignored when deploying a stack in swarm mode with a version 3 Compose file.
I tried to deploy Traefik with configuration stored in Consul to Swarm.The scenario was:
- I had to deploy first my storage backend:
consul
- Then deploy an instance of traefik which would upload config to consul:
traefik_init
- And finally I could deploy all traefik instances with consul backend:
traefik
I was not able to deploy consul
, traefik_init
and traefik
in the same stack.Since I was alreay using Ansible I created a playbook doing the following
- deploy
consul
stack - wait for all consul nodes to be synced
- start
traefik_init
as a service with only 1 replica - wait for the configuration to be stored in consul
- deploy
traefik
stack.
I could have deployed all services in same stack if I chose to override both ENTRYPOINT
and CMD
of containers to use a script that wait for needed services to be up and then execute command at startup.
If I were not using Ansible already I would definitely have gone that way.
You can take a look at wait-for-it (pure bash script to test and wait on the availability of a TCP host and port) or wait-for(script to wait for another service to become available) for examples.
You can also find an example at https://docs.docker.com/compose/startup-order/