-1

I have a Python application to expose a REST API. The Python server is running on http://127.0.0.1:5000 I have another application written in NodeJS to wrap the API coming from Python and expose another API as a passthrough. The Node server is running on http://localhost:8080

I'm new to Docker, I'm building a docker image for the Node application (in MacOS Silicon). The problem is when I invoke the API using curl http://localhost:8080 The docker desktop says "Connection refused: /127.0.0.1:5000"

The following is the docker run command I'm using

docker run --platform linux/amd64 -d -v ./Config.toml -p 8080:8080 myApp/app:v0.1.0

I tried with the --network host flag with the docker run command, but it doesn't work since it ignores all the declared ports. And I tried with the http.server --bind 0.0.0.0 with the docker run command, but the result says "pull access denied for http.server"

How can I solve this?

David Johns
  • 1,254
  • 3
  • 19
  • 48
  • 1
    Does this answer your question? [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – Zeitounator Feb 17 '23 at 18:01
  • @Zeitounator I'm not sure, the linked question is something similar to MySQL which is not my case – David Johns Feb 17 '23 at 18:06
  • This is an automatic comment generated because I linked a duplicate. It answers your question which is how to connect to a service running on your host from one running inside a docker container. – Zeitounator Feb 17 '23 at 18:09

1 Answers1

0

curl http://127.0.0.1:5000 on host machine to see if server is actually running.

Check server accessibility from within container. Simply run the docker container on interactive it and try access the server from the container.

docker run --platform linux/amd64 -it myApp/app:v0.1.0 /bin/bash
curl http://127.0.0.1:5000

If this does not work, it's a network configuration issue in the container you should set up to allow access to host machine.

If it works, then bind NodeJs app to 0.0.0.0 to allow conns from any ip.

docker run --platform linux/amd64 -d -v ./Config.toml -p 8080:8080 myApp/app:v0.1.0 -host 0.0.0.0
Kreetchy
  • 688
  • 4
  • 14