axios
axios copied to clipboard
Request cannot connect to host inside docker container
I have nestjs application running in docker container. It uses HttpService which uses '@nestjs/axios' to call some service trough http. I get this error:
Error:
Error: connect ECONNREFUSED 127.0.0.1:8081
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1159:16)
Code:
const getRequest = lastValueFrom(
this.httpService.get("http://127.0.0.1:8081/").pipe(
map(resp => resp.data),
),
);
It works when not run in docker container. But I get error when run in container.
I don't think it is something that has to do with axios, try it with fetch and you'll see the same result.