How to assign different port to container replicas

2020-04-21 09:29发布

问题:

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.

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.

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.

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.

Thanks in advance.

回答1:

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.