Adding a service to a stack after the stack has been deployed Adding a service to a stack after the stack has been deployed docker docker

Adding a service to a stack after the stack has been deployed


When you deploy a stack like this:

docker stack deploy --with-registry-auth --compose-file docker-compose.yml my-stack

It creates a network called my-stack_default

So to launch a service that can communicate with services that are in that stack you need to launch them like this:

docker service create -name statefulservice --network my-stack_default reponame/imagename


It would help to have a working example, but:

My guess is you don't have the services on the same docker network. Even if you don't manually assign stack services to a network (which is fine), The stack command creates one where all services in that stack are attached to. You'll need to specify that overlay network in your subsequent service create commands so they can find each other in DNS and communicate inside the swarm.

For example, if I create a stack called nginx, it will add all those services (unless configured otherwise in stack file) to an overlay network called nginx_default