title: docker-compose can't connect to adjacent service via service name
body: <p>I have this docker-compose.yml that basically builds my project for e2e test.  It's composed of a postgres db, a backend Node app, a frontend Node app, and a spec app which runs the e2e test using cypress.
        version: '3'</p>
  
  <pre><code>  services:
      database:
        image: 'postgres'
      backend:
        build: ./backend
        command: /bin/bash -c "sleep 3; yarn backpack dev"
        depends_on:
          - database
      frontend:
        build: ./frontend
        command: /bin/bash -c "sleep 15; yarn nuxt"
        depends_on:
          - backend
      spec:
        build:
          context: ./frontend
          dockerfile: Dockerfile.e2e
        command: /bin/bash -c "sleep 30; yarn cypress run"
        depends_on:
          - frontend
          - backend
  </code></pre>
  
  <p>The Dockerfiles are just simple Dockerfiles that based off node:8 which copies the project files and run <code>yarn install</code>.  In the spec Dockerfile, I pass <code>http://frontend:3000</code> as FRONTEND_URL.</p>
  
  <p>But this setup fails at the <code>spec</code> command when my cypress runner can't connect to <code>frontend</code> with error:</p>
  
  <pre><code>  spec_1      |   &gt; Error: connect ECONNREFUSED 172.20.0.4:3000
  </code></pre>
  
  <p>As you can see, it resolves the hostname <code>frontend</code> to the IP correctly, but it's not able to connect. I'm scratching my head over why can't I connect to the frontend with the service name. If I switch the command on <code>spec</code> to do <code>sleep 30; ping frontend</code>, it's successfully pinging the container. I've tried deleting and let docker-compose recreate the network, I've tried specifying <code>expose</code> and <code>links</code> to the services respectively. All to no success.</p>
  
  <p>I've set up a sample repo here if you wanna try replicating the issue:
  <a href="https://github.com/afifsohaili/demo-dockercompose-network" rel="nofollow noreferrer">https://github.com/afifsohaili/demo-dockercompose-network</a></p>
  
  <p>Any help is greatly appreciated! Thank you!</p>