Getting address lookup failed when running node inside a docker container

Hi,

I am trying to access a nodejs service running inside a docker container but it keeps giving error.

I am hitting

curl -X GET http://revamp.intelehealth.org:5001/scaffold -H “Authorization: Basic $(echo -n test:test | base64)”

My docker command is

sudo docker run --network ih_openhim --name scaffold --rm -p 3000:3000 scaffold

My Dockerfile has

FROM node:18-buster
WORKDIR /app
COPY . /app
RUN npm install
CMD npm start
EXPOSE 3000

My docker network list is

NETWORK ID NAME DRIVER SCOPE
26044067beac bridge bridge local
99c1e811ad1c host host local
878ec7d0436a ih_openhim bridge local
0b718516b4f0 none null local

I have also tried

sudo docker run --network ih_openhim --name scaffold --rm -p 3000:5001 scaffold

but the error still says

2023-09-05 04:55:07.121 - info: [worker1] The channel that matches the request /scaffold is: Bootstrap Scaffold Mediator
2023-09-05 04:55:07.122 - info: [worker1] Storing request metadata for inbound transaction
2023-09-05 04:55:07.122 - info: [worker1] The request, ‘/scaffold’ is authorised to access Bootstrap Scaffold Mediator
2023-09-05 04:55:07.141 - error: [worker1] [64f66753c416130692d83d0b] Internal server error occured: Error: getaddrinfo EAI_AGAIN scaffold
2023-09-05 04:55:07.148 - info: [worker1] All routes completed for transaction: 64f66753c416130692d83d0b
2023-09-05 04:55:07.148 - error: [worker1] Error: getaddrinfo EAI_AGAIN scaffold
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26)
2023-09-05 04:55:07.149 - info: [worker1] stored primary response for 64f66753c416130692d83d0b
2023-09-05 04:55:07.151 - info: [worker1] Final status for transaction 64f66753c416130692d83d0b : Failed

Any idea what am I missing?

Thanks

You expose port 3000, then try to access 5001 in your curl command? Once you map the container port 3000 to the host port 3000, another time you map container port 5001 to host port 3000.

Which port does you node application bind? How do you make your application inside the container bind the modified port?

Docker can not magically know how to configure the application inside the container to listen on a specific port. As the application and/or image developer you should know how the application needs to be configured, and if you want the application port inside the container to be modifiable, you need to implement logic in your entry point script that takes care of it.

Thank you very much @meyay .

I followed the instructions given at this link

Node binds to 3000
Port exposed is 3000
There they are saying

curl -X GET http://localhost:5001/scaffold -H “Authorization: Basic $(echo -n test:test | base64)”

If you could take a min to look at the link , and suggest a way out?

Thanks

HI @meyay or anyone , I guess just need few pointers to set this up. Greatly appreciate it.

Thanks