简体   繁体   English

Docker Swarm模式下的浏览器服务容器

[英]Browser services' container in Docker Swarm mode

I've created 3 vm using docker-machine: 我已经使用docker-machine创建了3个虚拟机:

docker-machine create -d virtualbox manager1
docker-machine create -d virtualbox worker1
docker-machine create -d virtualbox worker2

these are theirs ip: 这些是他们的IP:

docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
manager   -        virtualbox   Running tcp://192.168.99.102:2376                                   v1.12.6
worker1   -        virtualbox   Running   tcp://192.168.99.100:2376           v1.13.0-rc5  
worker2   -        virtualbox   Running   tcp://192.168.99.101:2376           v1.13.0-rc5   

Then docker-machine ssh manager1 然后docker-machine ssh manager1

and: 和:

docker swarm init --advertise-addr 192.168.99.102:2377

then worker1 and worker2 join to the swarm. 然后worker1和worker2加入了集群。

Now i've created a overlay network as: 现在,我创建了一个覆盖网络:

docker network create -d overlay skynet

and deployed a service in global mode (1 task for node): 并以全局模式部署服务(节点有1个任务):

docker service create --name http --network skynet --mode global -p 8200:80 katacoda/docker-http-server

And there is effectively 1 container (task) for node. 实际上,节点有1个容器(任务)。

Now, i'd like accessing directly to my virtual host.. or, at least, i'd like browsing directly my service's container, because of i'd like developing a load balancer of my service with nginx. 现在,我想直接访问我的虚拟主机。或者,至少我想直接浏览我的服务的容器,因为我想用nginx开发我的服务的负载均衡器。 For doing that, in my nginx conf file, i'd like to point to a specific service container (ie now i have 3 node (1 manager and 2 workers) in global mode, so i have 3 tasks running-->i'd like to choose one of these 3 containers). 为此,在我的nginx conf文件中,我想指向一个特定的服务容器(即现在我在全局模式下有3个节点(1个管理器和2个工作器),所以我有3个任务在运行-> i' d想选择这3个容器之一)。 How can i do that? 我怎样才能做到这一点?

[edit]: i can point to my swarm nodes simply browsing to VM_IP:SERVICE_PORT , ie: 192.168.99.102:8200 , but there is still internal load balancing. [edit]:我可以指向我的VM_IP:SERVICE_PORT节点,只需浏览到VM_IP:SERVICE_PORT ,即: 192.168.99.102:8200 : VM_IP:SERVICE_PORT ,但是仍然存在内部负载平衡。

I was thinking that, if i point to a specific swarm node, i'll use container inside that specific node. 我当时在想,如果我指向特定的群集节点,则将在该特定节点内使用容器。 But nothing, for now. 但是暂时没有。

Adding to the answer @ben-hall provided above; 在上面提供的答案@ ben-hall中添加; Docker 1.13 will introduce an advanced syntax for the --publish flag, which includes a mode=host publish mode to publishing service ports (see the pull-request here: docker#27917 , and docker#28943 ). Docker 1.13将为--publish标志引入高级语法,其中包括用于发布服务端口的mode=host publish模式(请参阅此处的pull-request: docker#27917docker#28943 )。 Using this mode, ports of the containers (tasks) backing a service are published directly on the host they are running on, bypassing the Routing Mesh (and thus, load-balancer). 使用此模式,支持服务的容器(任务)的端口直接发布在它们正在运行的主机上,绕过路由网格(因此是负载均衡器)。

Keep in mind that as a consequence, only a single task of a service can run on a node. 请记住,因此,服务的单个任务只能在节点上运行。

On docker 1.13 and up; 在docker 1.13及更高版本上; the following example creates a myservice service, an port 80 of the task is published on port 8080 of the node that the task is deployed on. 下面的示例创建了一个myservice服务,任务的端口80发布在部署该任务的节点的端口8080上。

docker service create \
  --name=myservice \
  --publish mode=host,target=80,published=8080,protocol=tcp \
  nginx:alpine

Contrary to tasks that publish ports through the routing mesh, docker ps also shows the ports that are published for tasks that use "host-mode" publishing (see the PORTS column); 与通过路由网格发布端口的任务相反, docker ps还显示了为使用“主机模式”发布的任务发布的PORTS (请参阅“ PORTS列);

CONTAINER ID        IMAGE                                                                           COMMAND                  CREATED              STATUS              PORTS                           NAMES
acca053effcc        nginx@sha256:30e3a72672e4c4f6a5909a69f76f3d8361bd6c00c2605d4bf5fa5298cc6467c2   "nginx -g 'daemon ..."   3 seconds ago        Up 2 seconds        443/tcp, 0.0.0.0:8080->80/tcp   myservice.1.j7nbqov733mlo9hf160ssq8wd

Due to the way SwarmMode works with the IPVS Load Balancer (discussed at https://www.katacoda.com/courses/docker-orchestration/load-balance-service-discovery-swarm-mode ), it's not possible to just access a single container deployed as a service. 由于SwarmMode与IPVS负载均衡器一起工作的方式(在https://www.katacoda.com/courses/docker-orchestration/load-balance-service-discovery-swarm-mode上讨论),无法访问单个容器部署为服务。

Request for configuring the load balancer has an open Github issue at https://github.com/docker/docker/issues/23813 配置负载平衡器的请求在https://github.com/docker/docker/issues/23813上存在一个公开的Github问题

What you may find helpful is to use a proxy running on each node. 您可能会发现有用的是使用在每个节点上运行的代理。 This could be configured to only response to certain nodes request (in theory). 可以将其配置为仅响应某些节点的请求(理论上)。 Two which are designed around SwarmMode include: 围绕SwarmMode设计的两个包括:

https://github.com/vfarcic/docker-flow-proxy https://github.com/vfarcic/docker-flow-proxy

https://github.com/tpbowden/swarm-ingress-router https://github.com/tpbowden/swarm-ingress-router

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

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