Answers: <p>Docker actually provides DNS support for networking between containers. This means that if you define your database connection as:</p>
  
  <pre><code>http://redis:6379
  </code></pre>
  
  <p>This will resolve <code>redis</code> to the correct network address, given that you fulfill the following:</p>
  
  <ul>
  <li>All containers are on the same network</li>
  <li>The containers have been named</li>
  </ul>
  
  <p>This can either be done manually by starting both instances via the <a href="https://docs.docker.com/engine/reference/commandline/cli/" rel="nofollow noreferrer">cli</a> or automated with a <a href="https://docs.docker.com/compose/gettingstarted/" rel="nofollow noreferrer">docker compose</a> script, which is <em>my recommendation</em>. In the compose script, from version 3, you would define the both services (aka the containers):</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And at the end of the file, define the network both instances should be connected to:</p>
  
  <pre><code>networks:
    backend:
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-05T20:40:30.883Z
Answers: Version 2 of Docker Compose introduced [service configuration](https://docs.docker.com/compose/compose-file/compose-file-v2/#service-configuration-reference), 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.
Answers: chupasaurus
Answers: CC BY-SA 3.0
Answers: 2018-02-05T20:51:01.440Z
Answers: 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: https://docs.docker.com/compose/compose-file/compose-versioning/#version-2x-to-3x
Answers: Moritz
Answers: CC BY-SA 3.0
Answers: 2018-02-05T22:46:01.347Z
Answers: Look at [Releases page](https://github.com/docker/compose/releases/), 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+).
Answers: chupasaurus
Answers: CC BY-SA 3.0
Answers: 2018-01-04T05:25:30.743Z
Answers: 2018-01-04T05:25:30.743Z
Answers: Moritz
Body: <p>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 <a href="https://10.11.12.13:8443" rel="noreferrer">https://10.11.12.13:8443</a> 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?</p>
  
  <p>Can someone help regarding the issue?</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-12-22T22:16:12.667Z
Comments: 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
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-12-25T05:24:29.863Z
Comments: @Tensibai But how can I able to ping successfully to host from container ?
Comments: Gourav Singla
Comments: CC BY-SA 3.0
Comments: 2017-12-25T10:33:07.943Z
Comments: 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.
Comments: oryades
Tags: <docker><containers><networking>
Title: Networking between Docker containers
UserDisplayName: Gourav Singla
ThreadText: # Networking between Docker containers
  
  (Asked by: username_0 on 2017-12-22)
  
  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?
  
  **Tags:** docker, containers, networking
  
  > **Comments:**
  > **username_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  
  > **username_0**: @username_1 But how can I able to ping successfully to host from container ?  
  > **username_2**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2018-01-04. Score: 4
  
  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](https://docs.docker.com/engine/reference/commandline/cli/) or automated with a [docker compose](https://docs.docker.com/compose/gettingstarted/) 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:
  
  ```
  
  > **Comments:**
  > **username_4**: Version 2 of Docker Compose introduced [service configuration](https://docs.docker.com/compose/compose-file/compose-file-v2/#service-configuration-reference), 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.  
  > **username_3**: 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: https://docs.docker.com/compose/compose-file/compose-versioning/#version-2x-to-3x  
  > **username_4**: Look at [Releases page](https://github.com/docker/compose/releases/), 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+).  
  
  ---
  
  