I am deploying multiple stacks on a Docker swarm with docker compose.
Right now I have defined a network in my proxy stack compose file:
networks:
proxy:
driver: overlay
The other stacks reference this network the following way:
networks:
proxy_proxy:
external: true
The problem with this setup is that all other stacks now depend on the proxy stack. Removing the proxy stack (e.g in order to replace/restart it) will cause an error like this:
Failed to remove network 800w54tbh7w7clc4o8uc3y7no: Error response from daemon: rpc error: code = 9 desc = network 800w54tbh7w7clc4o8uc3y7no is in use by service 0zu489jepz586sguqrorv6j6hFailed to remove some resources from stack: proxy
Is there a way to define a network within docker compose that is not "owned" by one stack so that if it already exists any newly deployed stack will join it and if it doesn't it will be created?
That way there would be no dependency between the stacks.
I believe in such case the network is global to your cluster, and is not really a part of any particular stack.
I'd suggest to create it manually with docker network create
and refer to it as external
everywhere.
To create, I'd recommend to use some provisioning tool (like Ansible or Salt) or a shell script to run on any master node by hand. The point is, you won't have to remember the details (or the very fact you need to create this network) if you'll ever have to rebuild the cluster or create a clone. I don't think there is a way to create a compose file with just networks, thus a shell script recommendation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With