Docker swarm use local service instance

326 Views Asked by At

I try to update a project from a single host to multi host platform. So basically I want to switch from docker-compose deployment to docker swarm. My application look like that: example app

I have 2 application app1 and app2. app1 create a huge file for app2. The file is written on a data volume shared between app1 and app2 container. Previously I use a traefik routing to move from app1 to app2.

So now to do that, I create 3 global services (one for app1, one for app2 and one for traefik). It's working but the traefik can redirect to a different host when you switch from app1 to app2. (The red arrows in the following scheme)

(The traefik rules are like app1.domaine.com --> app1 service)

Topo swarm

So how I can limit the routing to local host service only ?

Thanks in advance for your help ;)

1

There are 1 best solutions below

2
On

It's a bit hard to infer the ideal solution here, but I'm not sure --global is really your best fit. Take a look at the documentation for --mount (https://github.com/docker/docker/blob/master/docs/reference/commandline/service_create.md#add-bind-mounts-or-volumes). I am wondering if a named volume shared by the service tasks (containers) might be a slightly better fit than trying to create a global service. That will create containers for this service on every single host in your cluster.

So how I can limit the routing to local host service only ?

Why exactly do you want to do this? Ideally you should be able to load balance between task instances within a service without issue. If you have to "stick" requests to one container pair, run only one instance of each and use a named volume.