简体   繁体   English

Docker swarm使用本地服务实例

[英]Docker swarm use local service instance

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. 所以基本上我想从docker-compose部署切换到docker swarm。 My application look like that: 我的应用看起来像这样: 示例应用

I have 2 application app1 and app2. 我有2个应用程序app1和app2。 app1 create a huge file for app2. app1为app2创建一个巨大的文件。 The file is written on a data volume shared between app1 and app2 container. 该文件写在app1和app2容器之间共享的数据卷上。 Previously I use a traefik routing to move from app1 to app2. 以前我使用traefik路由从app1移动到app2。

So now to do that, I create 3 global services (one for app1, one for app2 and one for traefik). 所以现在要做到这一点,我创建了3个全局服务(一个用于app1,一个用于app2,一个用于traefik)。 It's working but the traefik can redirect to a different host when you switch from app1 to app2. 它正在工作,但当你从app1切换到app2时,traefik可以重定向到不同的主机。 (The red arrows in the following scheme) (以下方案中的红色箭头)

(The traefik rules are like app1.domaine.com --> app1 service) (traefik规则类似于app1.domaine.com - > app1服务)

Topo swarm

So how I can limit the routing to local host service only ? 那么我如何才能限制到本地主机服务的路由?

Thanks in advance for your help ;) 在此先感谢您的帮助 ;)

It's a bit hard to infer the ideal solution here, but I'm not sure --global is really your best fit. 在这里推断出理想的解决方案有点困难,但我不确定 - --global真的是你最合适的。 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 ). 请查看--mounthttps://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. 如果必须将请求“粘贴”到一个容器对,则只运行每个容器对中的一个实例并使用命名卷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM