0

My Windows have a container running a project. That call an API like fake-server.com/api/data

Dockerfile
EXPOSE 3000

That API install in apache server localhost on my windows (not container) like

# hosts file
127.0.0.1 fake-server.com

But it get an error like

connect ECONNREFUSED 127.0.0.1:80

I run docker by

docker run -it -p 8080:3000 myproject

How to fix that thanks.

DeLe
  • 2,442
  • 19
  • 88
  • 133
  • Configure your application to use the special host name `host.docker.internal` to call back to the host (on Windows or MacOS). Avoid editing hosts files if at all possible. – David Maze Jun 27 '21 at 11:18

2 Answers2

1

I probably misunderstood your problem in my initial answer.

I think your docker container setup is right and that you are using the right port mapping:

docker run -it -p 8080:3000 myproject

Probably your problem has to do with the Apache configuration. You need to configure Apache properly for proxying requests to your API. You can do that by including something like the following in your Apache configuration:

ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

Please, read for instance this detailed article about the subject, it is not directly related with docker but I think can be of help in understand the problem and how to configure Apache properly.

jccampanero
  • 50,989
  • 3
  • 20
  • 49
  • thank but it seem not working. still error `connect ECONNREFUSED 127.0.0.1:80 at TCPConnectWrap.afterConnect [as oncomplete]` – DeLe Jun 27 '21 at 10:18
  • You are welcome ;). I think I misunderstood your setup. You Apache is installed in the machine, isn't it? Then, probably the problem has to do with the configuration of Apache. Please, first, can you verify that if you run `docker run -it -p 8080:3000 myproject`, with your old mapping, your application work properly by accessing `fake-server.com:8080/api/data` and `localhost:8080/api/data`? – jccampanero Jun 27 '21 at 10:24
  • More info: In my local machine I install `xampp` to virtual server and using `hosts` file windows to fake domain like `fake-server.com` as I description. Inside container, my project is `node server` and it get data from `fake-server.com` – DeLe Jun 27 '21 at 10:30
  • That is fine, thank you DeLe. But, when you run your container like this, `docker run -it -p 8080:3000 myproject`, are you able to access `fake-server.com:8080/api/data`in a browser or with postman or curl, or other tool? I mean, you need to configure Apache to proxy requests for your API, did you configure that stuff? – jccampanero Jun 27 '21 at 10:38
0

Make sure you are using the correct ip, docker is probably on another. Open prompt and run:

ipconfig

lsd
  • 504
  • 1
  • 4
  • 16