Docker containers communication ECONNREFUSED error on windows – Rajvir Singh Rai – Medium

I had one container who was exposing one API on the host machine and below was the endpoint

http://localhost:3000/getArticles

I built one more container who was going to consume this API. Whenever I tried to access the above endpoint on this second container I got the below error:

AxiosError: connect ECONNREFUSED 127.0.0.1:3000
port: 3000,
address: '127.0.0.1',
syscall: 'connect',
code: 'ECONNREFUSED',
errno: -111,

This was happening because localhost was referring to the container.

In order to access your local machine use host.docker.internal instead of localhost.

I used below url and the issue got resolved

http://host.docker.internal:3000/getArticles

Leave a Reply