Several docker stacks with the same compose file but different ports

412 views Asked by At

I would like to run several instances of a multi-container application at the same time using the same compose file. One of the containers in the application accepts websockets on a certain port.

I have an nginx proxy to forward different domains or locations to different instances of the application. The instances are actually different tenants using the application.

I would like to simply be able to run:

docker stack deploy -c docker-stack.yml tenant1
docker stack deploy -c docker-stack.yml tenant2

And somehow get different ports to the apps, which I then can use in the proxy to forward different websocket connections to different application instances, either using locations or virtual hosts.

So either:

ws://tenant1.mydomain.com

or

ws://mydomain.com/tenant1

How to configure the proxy to do this can surely be figured out. I've started to read a bit about: https://github.com/jwilder/nginx-proxy, which seems nice. However it requires that I set the virtual host name as environment variable for each app-instance and I can't seem to find a way to pass arguments with my docker stack deploy command?

Ideally I would like to not care about exact ports, they would rather be random. But they need to somehow be known to the nginx proxy to be able to forward. I want to easily be able to spin up a new appinstance (tenant) stack and just set up the proxy for that name (or even better if the proxy can handle that automatically with the naming of the app).

Bonus if both examples above works (both virtual host and location) since that would make it possible to test and develop without making subdomains / new domains.

Suggestions?

0

There are 0 answers