26

Once or twice a week, a Docker question comes up roughly like:

I am running a React application and an Express backend in Docker Compose. I have a Docker network configured. My React application calls fetch('http://backend/') using the Compose service name; why doesn't this work?

Some recent questions more or less of this form include this (using websockets), this (pure Node.js/MongoDB stack), this (misuses Docker-internal IP address), this (Axios), this (fairly clear example, Axios/Flask).

There is a good technical explanation to this (the application runs in the browser even if it is served from a container) and two reasonable answers (better is to run a reverse proxy; acceptable in a local environment is to publish a port from the backend container).

I haven't found a really clear highly-scored question that lays out the problem clearly, making it clear it's not dependent on the JavaScript browser library or the backend technology. I also haven't found a solid answer that describes the reverse-proxy setup. Is there a "best" question for this class of question?

(I'd also hope for a similar Kubernetes question, that has a better best answer using the Kubernetes Ingress system.)

1
  • 4
    I agree there should be a canonical for that for docker. Seems to be a common issue. But even more generally the application running in the browser won't have access to the same DNS as the backend. Even if you host that on just some server and that server can access "mydomain" that doesn't mean that the browser, which runs on a completely different machine, can also resolve "mydomain".
    – VLAZ
    Commented Aug 23, 2023 at 12:36

2 Answers 2

16

It sounds like you've painted a clear picture of why this question should exist and why none of the existing questions are duplicates of sufficient quality to be used for this purpose.

I'd say you should go ahead and create it.

2

I've asked and answered "Unknown host" error calling containerized backend from frontend, describing both the published-port approach and the reverse-proxy approach.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .