I'm using the Nodejs app with docker to be deployed on AWS ecs.
The problem is that api call on private DNS record return
error: getaddrinfo enotfound request
From research error looks like to be connected with DNS lookup (please feel free to comment if you have other theory), so I decided to set DNS servers and µextra_hostsµ on compose.
Even though everything builds, when I cat /etc/hosts in Dockerfile it's not changed.
Questions are:
- Should /etc/hosts be modified by extra_hosts.
- Can there be other reason for error:
getaddrinfo enotfound request
? All other api calls work except internal DNS which works once and after returns error:getaddrinfo enotfound.
- What's the best way to configure DNS and host with docker?
- Why is it working once and stops after?
this is how my docker-compose file looks:
version: '3'
services:
nodejs:
extra_hosts:
- "<name here>:<ip here>"
- "<name here>:<ip here>"
dns:
- <ip here>
- <ip here>
- <ip here>
network_mode: 'host'
build:
context: .
dockerfile: Dockerfile
Heres how docker file looks like
FROM alpine:latest
RUN apk add --update nodejs nodejs-npm && apk add g++ make python
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN cat /etc/hosts
EXPOSE 80
CMD npm start
Here's the docker build output
Sending build context to Docker daemon 11.58MB
Step 1/11 : FROM alpine:latest
---> f70734b6a266
Step 2/11 : RUN apk add --update nodejs nodejs-npm && apk add g++ make python
---> Using cache
---> b173538c6ce5
Step 3/11 : WORKDIR /usr/src/app
---> Using cache
---> 0186bcca617d
Step 7/11 : RUN npm install
---> Using cache
---> 546f707d5fea
Step 8/11 : COPY . .
---> b66f4bec9d93
Step 9/11 : RUN cat /etc/hosts
---> Running in 1c48f0426713
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 1c48f0426713
Removing intermediate container 1c48f0426713
---> 858735acc4a6
Step 10/11 : EXPOSE 80
---> Running in dd7a8ae0669a
Removing intermediate container dd7a8ae0669a
---> 907a3dafb4fc
Step 11/11 : CMD npm start
---> Running in a3dd69c6ec3b
Removing intermediate container a3dd69c6ec3b
---> cda2214b2761
Successfully built cda2214b2761
Successfully tagged test:latest