I have a docker container 'A' on a host listening on port>8443/tcp I have another container 'B' on same host how wants to talk to 'A' on 8443 via host. Thus when I run command curl inside B it gives me error as 'No route to host' but I can ping successfully. I am not sure what else I am missing?

Can someone help regarding the issue?

  • 1
    Your container has exactly what it says: no route toward host, your container has a different IP and you'll have to give proper parameter to docker run for it to access your host, I can't remember them from memory but that's what to search for
    – Tensibai
    Dec 22, 2017 at 22:16
  • @Tensibai But how can I able to ping successfully to host from container ? Dec 25, 2017 at 5:24
  • I've tried to reproduce, started container A with command 'nc -l 8443' to listen to that port and started container B with command 'nc HOST_IP 8443' and it worked, containers could talk via host.
    – oryades
    Dec 25, 2017 at 10:33

1 Answer 1


Docker actually provides DNS support for networking between containers. This means that if you define your database connection as:


This will resolve redis to the correct network address, given that you fulfill the following:

  • All containers are on the same network
  • The containers have been named

This can either be done manually by starting both instances via the cli or automated with a docker compose script, which is my recommendation. In the compose script, from version 3, you would define the both services (aka the containers):

version: "3"
    build: ./web
    container_name: web
      - backend
    command: bash -c "./start.sh"

    image: redis:3.2
    container_name: redis
      - backend

And at the end of the file, define the network both instances should be connected to:

  • Version 2 of Docker Compose introduced service configuration, not 3. Also v3 is made for Docker Swarm while v2 has more host-oriented features, both are being developed independently and v2 is recommended for usage outside of Swarm cluster. Feb 5, 2018 at 20:40
  • You are right that it was introduced in v2. However, I could not find a reference supporting that they are being developed independently. 3 seems to be a simplification of 2: docs.docker.com/compose/compose-file/compose-versioning/…
    – Moritz
    Feb 5, 2018 at 20:51
  • Look at Releases page, new features are still added for v2, while some features from v2 are now supported in v3 (i.e. volume names in 3.4 which were in 2.1+). Feb 5, 2018 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.