Multiple deployments of the same multi container app

My case is more complex than just this, but here’s the scenario.

I have an application that has a database server, this is in a container started as app1-db.

There is also an application in JBOSS in another container, app1-web, which is using app1-db because that’s configured in various JDBC configuration files within JBOSS. This isn’t using the old linking, but instead using an OVERLAY network called app1-net, with host names. So the JDBC in app1-web is using app1-db hostname in the JDBC config.

So far so good. But

What is best way to re-deploy this into the same docker swarm as another separate stack of containers? For if you want test and production?

I can deploy into a new OVERLAY network, called app2-net, and containers in there obviously can’t see the services provided by app1-net and that’s good, but my JBOSS configs are still trying to talk to the database using hostname app1-db.

Do I pass in (say APP_NAME=app2) an environment variable and have some script that changes config files based on $APP_NAME ?

Or, can I ‘hard code’ some generic names for linked containers, and let docker networking sort out which ones it goes to?

It would be nice if perhaps when looking up the hostname ‘db’ when running in app1-net , you’d get app1-db , and when looking up same hostname ‘db’ in app2-net, you’d get app2-db. Is this possible?


Of course it’s possible. You use --net-alias to create static well known names within each --net

I’m very happy about this