Image for docker and host port
Describe the bug Following the example of the repo in /reflex/docker-example/simplen-one-port everything works fine as long as you don't change the host port when doing a docker run or docker compose.
If you change the host port you receive a:
Cannot connect to server: websocket error. Check if server is reachable at ws://localhost:8000/_event
To Reproduce Run a: docker run -p 9999:8080 reflex-simple-one-port
Expected behavior The idea is to be able to have the frontend and backend in the Docker image and be able to change the host port at will when starting the container with a Docker run since the backend is not going to be used externally.
Specifics (please complete the following information):
- Python Version: Python 3.13.5
- Reflex Version: 0.8.0
- OS: Any OS
- Browser (Optional): Any browser
Additional context The test was performed with an empty reflex init, and installing the example from https://reflex.dev/docs/getting-started/introduction/ to have the states.
Thanks
Odón
The problem here is that the frontend (javascript) is built into the container image, and whatever REFLEX_API_URL is set to at build time, will be where the frontend expects to find the backend. The exception to this logic is when accessing the frontend over TLS when the api url is non-TLS. In that case, the frontend assumes the backend is listening on the same host/port as the frontend and using some reverse proxy to route the traffic.
So if you had some other TLS-terminating proxy/load balancer in front of the single port docker container (like on platform services such as render or railway), then it just works regardless of what port is used in the inner layer, because the client only sees the TLS connection and tries to connect to the backend at the same address.
I could see this turning into a feature request where if the REFLEX_API_URL is set to some special value, then the frontend would always try to connect back on itself. maybe something like REFLEX_API_URL=:// could indicate "reuse the schema and hostname of the frontend"
Of course, I understand you perfectly.
But for the self-hosted world, which is what this app is intended for, not being able to change the host port when you launch a container from an image on DockerHub isn't understandable, because on those machines, there might be 50 containers launched with their own custom host ports.
It would be great if this became a request so I could somehow customize the host port at will.
Thanks,