如何为不同的Zookeeper Docker容器设置不同的管理端口?

mpgws1up  于 2022-12-09  发布在  Apache
关注(0)|答案(3)|浏览(247)

I am creating a cluster of three zookeeper docker containers on a Single system. Admin server of the first zookeeper docker is up using port 8080, so for other two Zoo containers, it is giving "Failed to bind to /0.0.0.0:8080, address in use". I am using zoo version as "zookeeper:3.5.6".
Now my question is how to assign different admin port to the zookeeper admin server other than 8080?
I have tried different options to set the admin server on different ports, but nothing worked.

1) - zookeeper.admin.serverPort=8078
2) - ZOO_CFG_EXTRA="admin.serverPort=8077"
3) - admin.serverPort=8078

Below is the docker compose for one zookeeper.

zk2:
  hostname: ${LOCAL_HOST}
  image: ${ZOOKEEPER_IMAGE}
  environment:
    - u=${USER}:${USER}
    - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=2048m
    - ZOO_MY_ID=${ZOO_MY_ID2}
    - ZOO_SERVERS=${ZOO_SERVER_1} ${ZOO_SERVER_2} ${ZOO_SERVER_3}
    - ZOO_ADMINSERVER_ENABLED=true
    - ZOO_STANDALONE_ENABLED=false
    - zookeeper.admin.serverPort=8078
  volumes:
    - ${VOLUMES_PATH}/zk2/data:/data
    - ${VOLUMES_PATH}/zk2/logs:/datalog
  network_mode: "host"
  ports:
    - ${ZOOK_CL_PORT2}:${ZOOK_CL_PORT2}
    - ${ZOOK_SR_PORT2}:${ZOOK_SR_PORT2}
    - ${ZOOK_EL_PORT2}:${ZOOK_EL_PORT2}
    - ${ZOOK_ADM_PORT2}:8078"

Can anyone suggest me how to do that?

7ajki6be

7ajki6be1#

Considering the docker compose file you posted, the problematic element is the network_mode: "host" . Citing the official documentation:
https://docs.docker.com/network/host/
If you use the host network mode for a container, that container’s network stack is not isolated from the Docker host (the container shares the host’s networking namespace), and the container does not get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container’s application is available on port 80 on the host’s IP address.
So, in fact, every one of the three zookeeper quorum members that you fire up is competing on allocating the 8080 port, ignoring the port binding you defined later on.

ix0qys7i

ix0qys7i2#

管理服务器端口8080仅在容器内可用,直到您使用端口Map公开它。如果您要将该端口公开给Docker主机,您应该为两个zookeeper容器分配不同的端口Map。
在这种情况下,您尝试更改容器的内部管理服务器端口,但这不是必需的。

version: '3.4'

services:
  zoo1:
    image: 'zookeeper'
    ports:
      - '2181:2181'
      - '8080:8080'
    environment:
      ZOO_SERVER_ID: 1
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"
  zoo2:
    image: 'zookeeper'
    ports:
      - '3181:2181'
      - '8078:8080'
    environment:
      ZOO_SERVER_ID: 2
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_ADMINSERVER_ENABLED: "true"
      ZOO_SERVERS: "zoo1:2888:3888,zoo2:2888:3888"

zoo 1-端口8080在容器内可用,我们将同一端口公开给Docker主机。zoo 2-端口8080在容器内可用,但我们将不同的端口(8078)公开给Docker主机。

现在,您可以从Docker主机使用端口8080访问第一个容器的接口,使用端口8078访问第二个容器的接口。

q1qsirdb

q1qsirdb3#

简单的方法

ZOO_ADMIN_SERVER_PORT_NUMBER:9999

ZOO管理员服务器端口号:管理服务器端口。默认值:8080
bitnami/zookeeper Reference URL

相关问题