如何在docker swarm中为容器副本分配不同的端口 [英] How to assign different port to container replicas in docker swarm

查看:333
本文介绍了如何在docker swarm中为容器副本分配不同的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将docker容器的风暴管理器部署在具有副本3的docker swarm模式下。现在,我们要通过浏览器访问管理器登录。

We are deploying storm supervisor with docker container in docker swarm mode with replica 3. Now we want to access supervisor logs on through browser.

我们公开了端口8080我们可以在其上访问Storm UI。一切正常。现在,storm也将其日志文件公开在端口8000上。由于我们只有一个nimbus和3个超级用户,因此通过端口8000访问nimbus日志非常容易。

We have exposed port 8080 on which we can access storm UI. This is working fine. Now storm also exposes their log files on port 8000. As we have only one nimbus and 3 supervisor, accessing nimbus logs through port 8000 was pretty easy.

我们面临的问题在使用docker swarm服务部署的主管上。在docker swarm服务中,我们无法为不同的容器传递不同的端口。

The problem we faced on supervisor which is deployed using docker swarm service. And in docker swarm service we cannot pass different port for different container.

当前docker swarm服务在所有容器上公开相同的端口。
我们真正想要的是

currently docker swarm service exposes same port on all the container. What we really want is like

port    container
8011    supervisor1:8000
8012    supervisor2:8000
8013    supervisor3:8000

我们如何实现这一目标。

How can we achieve this.

预先感谢。

推荐答案

理想情况下,Swarm服务中的任务不应唯一或包含彼此的唯一数据。我知道有几种方法可以解决此问题,但它总是让人感到不理想或骇人听闻,尤其是当您处理的持久性数据量需要与任务一对一匹配时。

Ideally, tasks in a Swarm service should not be unique or contain unique data from one another. I know there are a few ways around this but it always feels non-ideal or hackish, especially when you're dealing with persistent data volumes that need a 1-to-1 match to a task.

我建议您将三个副本分成三个单独的服务。我知道这听起来需要做更多的工作,但是在单个堆栈文件中,由于它们是唯一的容器,因此可以灵活地处理它们上的各个端口和卷。

I'd recommend you split the three replicas out into three separate services. I know it sounds like more work, but in a single stack file, it'll give you the flexibility to deal with individual ports and volumes on them since they are unique containers.

这篇关于如何在docker swarm中为容器副本分配不同的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆