Docker not able to connect via host IP or localhost

I have created a docker image which runs kafka inside the container. I have also done port mappings in the docker-compose.yml for mapping the host ports with container ports.

After bringing up the docker image (using docker-compose), I am able to see that the docker image is up and running and a container is also started as shown below:

  • Symfony3 fetch wrong data from database
  • Docker cache confusion
  • AWS ECR image list
  • How to populate a Mysql docker container during build of another container?
  • Avoid hard coding the mysql container ip in my apache container script
  • Docker + WerckerCi: Tag not found
  • e39cd6452307        dockerregistry:5000/confluent:latest   "/"              10 hours ago        Up 10 hours>8081/tcp,>2181/tcp,>9092/tcp   confluent

    ‘ps-ef | grep docker’ also provides me the following result:

    root      6594  5257  0 Jan17 ?        00:00:00 docker-proxy -proto tcp -host-ip -host-port 9920 -container-ip -container-port 9092
    root      6605  5257  0 Jan17 ?        00:00:00 docker-proxy -proto tcp -host-ip -host-port 8081 -container-ip -container-port 8081
    root      6617  5257  0 Jan17 ?        00:04:22 docker-proxy -proto tcp -host-ip -host-port 2108 -container-ip -container-port 2181

    Weird thing starts here:

    If I try to connect to service running inside the container from my host machine by using container IP and port (IP:, Port: 2181), my connection is successful and I get proper response.

    However, If I try to connect to the service from host machine using the mapped host IP and port(using 10.xx.xx.xx:2108), I get a connection refused message. (xx is just used for masking my machine ip)

    Also, ‘telnet 10.xx.xx.xx 2108’ works fine.

    What could be the problem in this case. I have docker version 1.7.1 and docker-compose version 1.5.0

    Please help.

  • Putting databases in their own Docker containers?
  • How can I force ssl connections in Percona server using Docker?
  • How to install oracle in mac using docker
  • Docker Datacenter: Error x509 certificate signed by unknown authority UCP 2.0.0 and DTR 2.1.0 with external certificates
  • Which application is the docker binary from?
  • Docker mounted volume not tracking nginx log files
  • 2 Solutions collect form web for “Docker not able to connect via host IP or localhost”

    As i can see that it is working fine inside the container using container ip and port ,that points to


    file , may be port mapping is not done there properly.

    Could you please upload your docker-compose because the only issue is of port as it is not exposed properly.
    Also you can check in your docker run command if the

    -p port:port

    is actually the port you want to expose or not.

    I had the same problem and was able to fix it by specifying the host that the server within the container uses. See my answer here: Access Docker forwarded port on Mac

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.