Ewgenij Sokolovski
Ewgenij Sokolovski

Reputation: 967

Zookeeper in Docker

I run zookeeper in a docker container on my Windows 7 machine. I use docker-compose and defined the ports: ['2181:2181'] mapping inside. The docker terminal shows me the zookeeper instance running: b3169443e7ee confluentinc/cp-zookeeper:3.3.0 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp zookeeper

But when I execute netstat -an in Windows terminal I do not see the 2181 port open. Neither can I connect to zookeeper using putty telnet on localhost port 2181. What could be the problem? As far as I understand the zookeeper ports are not exposed to the host. But they should be as I included the ports mapping in the docker-compose .yaml file.

Upvotes: 1

Views: 3954

Answers (2)

Ewgenij Sokolovski
Ewgenij Sokolovski

Reputation: 967

OK, finally I found out the reason. Since on Windows 7 you have to run your docker container in a virtual box running a linux system, the docker container sees the virtual box system as its host, not the original Windows 7 machine. Therefore the port mapping guest-to-host maps the port 2181 of the docker container to the 2181 port of the linux system in virtual box and NOT to the 2181 port of the "real" Windows 7 host. So, in order to connect to zookeeper, I had to retrieve the IP of the virtual box machine using docker-machine ls and then connect to port 2181 on that IP.

Upvotes: 1

yamenk
yamenk

Reputation: 51758

This is a known issue with localhost on windows. You need to use the container IP address. You can find it by running the command

docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' <container>

For more info check: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

Upvotes: 1

Related Questions