5

I have a docker container 'A' on a host 10.11.12.13 listening on port 0.0.0.0:8443->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 https://10.11.12.13:8443 inside B it gives me error as 'No route to host' but I can ping 10.11.12.13 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 '17 at 22:16
  • @Tensibai But how can I able to ping successfully to host from container ? – Gourav Singla Dec 25 '17 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 '17 at 10:33
3

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

http://redis:6379

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"
services:
  web:
    build: ./web
    container_name: web
    networks:
      - backend
    command: bash -c "./start.sh"

  redis:
    image: redis:3.2
    container_name: redis
    networks:
      - backend

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

networks:
  backend:
  • 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. – chupasaurus Feb 5 '18 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 '18 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+). – chupasaurus Feb 5 '18 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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