A web-app in Node.js connects to an api with axios.
import axios from 'axios'
export function fetchList() {
return axios.get('https://api.website.dev/v1/posts')
}
The api works well, all is fine.
Now, I use docker-compose
to run the exact same nodejs web app inside a container.
docker-compose.yml:
version: "3.1"
services:
nodejs:
image: node:alpine
working_dir: /home/app
restart: always
ports:
- "8000:8080"
volumes:
- ../nodejs:/home/app
command: ["npm", "start"]
The axios call to the Rest API returns an error:
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
…
How to make the nodejs app connect to the api from a docker container?