axios icon indicating copy to clipboard operation
axios copied to clipboard

Request cannot connect to host inside docker container

Open viktor111 opened this issue 3 years ago • 1 comments

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.

viktor111 avatar Jul 20 '22 10:07 viktor111

I don't think it is something that has to do with axios, try it with fetch and you'll see the same result.

khobiziilyes avatar Jul 21 '22 12:07 khobiziilyes