title: Docker containers: curl between containers not working
body: <p>I have multiple docker containers in the same network. I am trying to use curl on containerA to get the result from an API on test01.docker container . </p>
  
  <p>I run this command on container A:</p>
  
  <pre><code>curl -s test-01.docker:8031/app?status -v
  </code></pre>
  
  <p>The output is as follows:</p>
  
  <pre><code>* Hostname was NOT found in DNS cache
  *   Trying 172.19.0.24...
  * connect to 172.19.0.24 port 8031 failed: Connection refused
  * Failed to connect to test-01.docker port 8031: Connection refused
  * Closing connection 0
  </code></pre>
  
  <p>When I try to ping test01.docker from containerA using the following command:</p>
  
  <pre><code>ping test-01.docker
  </code></pre>
  
  <p>It is successful. </p>
  
  <p>When I do docker ps, It shows the following information. In my </p>
  
  <pre><code>43823212be7e        mytestimage        "/docker-entrypoint.s"   53 seconds ago       Up 47 seconds       22/tcp, 2812/tcp, 5060-5061/tcp, 6970-6971/tcp, 8002/tcp, 8030-8031/tcp, 8033/tcp, 8071/tcp, 8888/tcp, 9020-9023/tcp   containerA
  </code></pre>
  
  <p>This shows that port 8031 is exposed. I'm unable to figure out why curl is failing on this. When I run following command on test-01.docker, it gives me correct output:</p>
  
  <pre><code>curl -s localhost:8031/app?status
  </code></pre>
  
  <p>Not sure why its not working from other containers in same network. Please tell me if I'm missing something. </p>
  
  <p>Update: My docker-compose file looks like this:</p>
  
  <pre><code>  version: '2'
  
    services:
      test-01.docker:
        image: ##############
        expose:
          - 22
          - 2812
          - 8031
        hostname: test-01
        domainname: docker
  </code></pre>