title: How to connect a Node.js app to an http rest API from a docker service?
body: <p>A web-app in Node.js connects to an api with axios.</p>
  
  <pre><code>import axios from 'axios'
  
  export function fetchList() {
    return axios.get('https://api.website.dev/v1/posts')
  }
  </code></pre>
  
  <p>The api works well, all is fine. </p>
  
  <hr>
  
  <p>Now, I use <code>docker-compose</code> to run the exact same nodejs web app inside a container.</p>
  
  <p>docker-compose.yml: </p>
  
  <p>version: "3.1"</p>
  
  <p>services:</p>
  
  <pre><code>  nodejs:
      image: node:alpine
      working_dir: /home/app
      restart: always
      ports:
        - "8000:8080"
      volumes:
        - ../nodejs:/home/app
      command: ["npm", "start"]
  </code></pre>
  
  <p>The axios call to the Rest API returns an error: </p>
  
  <pre><code>error { Error: getaddrinfo EAI_AGAIN api.domain.dev:443
    at Object.exports._errnoException (util.js:1024:11)
    at errnoException (dns.js:55:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
  code: 'EAI_AGAIN',
  errno: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: 'api.domain.dev',
  host: 'api.domain.dev',
  port: 443,
  config:
   { adapter
  …
  </code></pre>
  
  <p><strong>How to make the nodejs app connect to the api from a docker container?</strong></p>