'How to set different admin ports for different Zookeeper Docker containers?
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?
Solution 1:[1]
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.
Solution 2:[2]
Admin server port 8080 is available only inside the container until you expose it with port mappings. If you want to expose the port to docker host you should assign different port mappings to both of your zookeeper container.
In this case, you are trying to change the container's internal admin server port which is not required. You can take the example of following docker-compose file -
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"
zoo1 - Port 8080 is available inside the container and we are exposing the same port to the docker host. zoo2 - Port 8080 is available inside the container but we are exposing different port(8078) to the docker host.
Now you can access the interface using port 8080 for first container and 8078 for the second container from your docker host.
Solution 3:[3]
Easy way to do this
ZOO_ADMIN_SERVER_PORT_NUMBER:9999
ZOO_ADMIN_SERVER_PORT_NUMBER: Admin server port. Default: 8080
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arvanitis Christos |
| Solution 2 | Ravi |
| Solution 3 | Willie Cheng |
