3

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:

  1. Should /etc/hosts be modified by extra_hosts.
  2. 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.
  3. What's the best way to configure DNS and host with docker?
  4. 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

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
OttoV
  • 214
  • 1
  • 3
  • 14
  • Can you please post the output of Dockerfile build – nischay goyal May 26 '20 at 09:18
  • Small question, Why `172.17.0.2 1c48f0426713` IP is coming with container id? It should be qualified name over there for extra-hosts – nischay goyal May 26 '20 at 09:28
  • For an idea of how docker-compose and Dockerfile interacts: 1. Build of the images (via Dockerfile, or via image) 2. Run of the containers, adding all info from docker-compose. So, yes, at the build time, it makes sense that your `/etc/hosts` is not **yet** changed properly. This does not fully answer the question, yet, but clear this already. – β.εηοιτ.βε May 26 '20 at 09:35
  • @β.εηοιτ.βε where do you think I should look for the problem. P.S it only errors on deployment, from local mac everything works just fine. – OttoV May 26 '20 at 09:41
  • I don't remember if you can do this with AWS, but if you can, try to `docker run -ti hash-of-the-container ash` in order to jump in the problematic container, then do a debugging from there (first `cat` the hosts files, then do things like using `ping` or `nc`) – β.εηοιτ.βε May 26 '20 at 09:46
  • Can you run the container and paste the output of /etc/hosts ? – nischay goyal May 26 '20 at 09:46
  • 1
    Trying to directly manage `/etc/hosts` usually isn't a good idea, Docker or otherwise: the hosts files in different contexts can get out of sync and you can be in a state where things work for mysterious reasons on one system but not another. On AWS you can set up internal DNS using [Route 53](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/Welcome.html); debugging your actual DNS problem is probably a better approach than trying to work around it. – David Maze May 26 '20 at 10:38
  • @OttoV Did you successfully able to implement this, if yes please do share some resources. – krishna chaitanya Apr 17 '23 at 04:36

1 Answers1

0

Turns out that aws fargate has only one network, which awsvpc and it does not allow modifications on host file or specification of dns server.

Worth mentioning that after tons of research we did not try this suggestion

Not sure if it works but still...

OttoV
  • 214
  • 1
  • 3
  • 14