Reputation: 14846
I have multiple stacks running in my swarm. The stacks are created from compose files. For illustrative purposes let's say I have the following:
Stack 1
- Nginx container
Stack 2
- Web App Container
- Database Container
- Cache Container
- SMTP Container
Stack 3
- Web App Container
- Database Container
When I deploy these stacks docker creates an overlay network so I have 3 independent overlay networks for each stack.
What I would like to do is make it so the Web App Container
in Stack 2 & 3 have access to the Stack 1 overlay network so that I can proxy_pass incoming connections without having to expose the port to the internet.
The docker website only seems to have an explanation for the legacy swarm networking: https://docs.docker.com/compose/networking/
That page says for stacks networking to refer to this page: https://docs.docker.com/engine/reference/commandline/stack_deploy/
I cannot see any information about networking on that page so i am a bit stuck.
Inside the web app service definition I have tried adding:
networks:
- nginx_default
This is the network name as shown by running docker network ls
but I get an error message that this network is not defined.
What is the right way to get my web app containers and my nginx container on the same private network?
Upvotes: 1
Views: 1235
Reputation: 14846
My issue was I needed to declare the network as external. Here is working sample config for stack 2:
version: "3.8"
networks:
stack2:
nginx:
external: true
services:
db:
networks:
stack2:
image: mysql:5.7
webapp:
networks:
stack2:
nginx:
image: webapp
This will connect webapp to the nginx network but the database wont be exposed to it.
Upvotes: 2