I a newbie to working with fastapi. I have a main.py inside docker container.When I connect to fastapi using
uvicorn main:app —-reload
from my container.I am prompted to connect to http://127.0.0.1:8000. On copying the address to Firefox I am getting the error:
unable to connect.
How can I connect to fastapi server ?
P.S The git branch I am working from was developed by another colleague so I have little to no idea how was fastapi was set up inside the docker
You need to use the command
uvicorn main:app --reload --host 0.0.0.0
Your docker container is like a computer, which is independent. Thus it does not allow access from external sources. With the --host option, you allow external connections (outside of localhost from the point of view of the container). Basically, docker's localhost is different from your computer's localhost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With