title: docker-compose service cannot access another service through its name
body: <p>I am quite new to docker but after watching a few tutorials I gathered that if I wanted my services to have common code I had to use docker-compose.</p>
  <p>This is my directory structure:</p>
  <pre><code>- project
     - docker-compose.yml
     - packages
         - common
            - src
               - eureka
                  - eureka-helper.js
         - gateway
            - Dockerfile
            - src 
               - (some more directories and files)
            - server.js
         - users
            - Dockerfile
            - src 
               - app.js
               - (some more directories and files)
  </code></pre>
  <pre><code>version: '3'
  
  services:
      eureka:
          image: springcloud/eureka
          ports:
              - &quot;8761:8761&quot;
      gateway: 
          build:
              context: ./
              dockerfile: ./packages/gateway/Dockerfile
          ports:
              - &quot;3000:3000&quot;
          links:
              - eureka
      users: 
          build:
              context: ./
              dockerfile: ./users/Dockerfile
          ports:
              - &quot;3004:3004&quot;
          links:
              - mongo
              - eureka
      mongo:
          image: mongo
          volumes:
              -  C:\Users\myUser\docker\mongodb-data:/data/db
          ports: 
              - &quot;27017:27017&quot;
  
  </code></pre>
  <p>My server.js (inside gateway) and app.js (inside users) call a function inside eureka-helper that registers with Eureka.</p>
  <pre><code>eurekaHelper.registerWithEureka('gateway', eureka, port);
  </code></pre>
  <p>But it seems that server.js doesn't have a value for this eureka:</p>
  <pre><code>gateway_1  | /opt/app/gateway/server.js:27
  gateway_1  | eurekaHelper.registerWithEureka('gateway', eureka, port);
  gateway_1  |                                            ^
  gateway_1  |
  gateway_1  | ReferenceError: eureka is not defined
  </code></pre>
  <p>As per this: <a href="https://docs.docker.com/compose/networking/" rel="nofollow noreferrer">https://docs.docker.com/compose/networking/</a>, it doesn't seem that I really need the link in docker-compose:</p>
  <blockquote>
  <p>Links allow you to define extra aliases by which a service is reachable from another service. They are not required to enable services to communicate - by default, any service can reach any other service at that service’s name.</p>
  </blockquote>
  <p>... but gateway is not able to reach eureka anyways.</p>
  <p>Any idea if I'm missing something.</p>
  <p>When I do inspect in gateway:</p>
  <pre><code>        &quot;Networks&quot;: {
              &quot;*project*_default&quot;: {
                  &quot;IPAMConfig&quot;: null,
                  &quot;Links&quot;: null,
                  &quot;Aliases&quot;: [
                      &quot;gateway&quot;,
                      &quot;a358b371de9d&quot;
                  ],
                  &quot;NetworkID&quot;: &quot;d986ee77bf6181e9dd59711650359dc49fd8ce3fc34c6772133a0049ab55bd3b&quot;,
                  &quot;EndpointID&quot;: &quot;9633a7affe435793345342d4f6d00d5bef43d2267676448dfde0f97d75d5f7af&quot;,
                  &quot;Gateway&quot;: &quot;172.19.0.1&quot;,
                  &quot;IPAddress&quot;: &quot;172.19.0.3&quot;,
                  &quot;IPPrefixLen&quot;: 16,
                  &quot;IPv6Gateway&quot;: &quot;&quot;,
                  &quot;GlobalIPv6Address&quot;: &quot;&quot;,
                  &quot;GlobalIPv6PrefixLen&quot;: 0,
                  &quot;MacAddress&quot;: &quot;02:42:ac:13:00:03&quot;,
                  &quot;DriverOpts&quot;: null
              }
          }
  </code></pre>
  <p>When I do inspect in eureka:</p>
  <pre><code>        &quot;Networks&quot;: {
              &quot;*project*_default&quot;: {
                  &quot;IPAMConfig&quot;: null,
                  &quot;Links&quot;: null,
                  &quot;Aliases&quot;: [
                      &quot;eureka&quot;,
                      &quot;17a218bf6e9e&quot;
                  ],
                  &quot;NetworkID&quot;: &quot;d986ee77bf6181e9dd59711650359dc49fd8ce3fc34c6772133a0049ab55bd3b&quot;,
                  &quot;EndpointID&quot;: &quot;43f4a9eb9efd4d30ad65d2c943065b8fb32ed50822bd553e07a2b0020c173fec&quot;,
                  &quot;Gateway&quot;: &quot;172.19.0.1&quot;,
                  &quot;IPAddress&quot;: &quot;172.19.0.2&quot;,
                  &quot;IPPrefixLen&quot;: 16,
                  &quot;IPv6Gateway&quot;: &quot;&quot;,
                  &quot;GlobalIPv6Address&quot;: &quot;&quot;,
                  &quot;GlobalIPv6PrefixLen&quot;: 0,
                  &quot;MacAddress&quot;: &quot;02:42:ac:13:00:02&quot;,
                  &quot;DriverOpts&quot;: null
              }
          }
  </code></pre>