s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.94k stars 171 forks source link

Can't open http://0.0.0.0:8000 #127

Closed writeson closed 2 years ago

writeson commented 2 years ago

Maybe I'm being dense, but I can't seem to access the web server. I've got the containers running following the README, but navigating to HTTP://0.0.0.0:8000 brings up nothing.... What am I missing?

s3rius commented 2 years ago

@writeson How do you start the app?

writeson commented 2 years ago

From a Mac terminal command line: docker-compose -f deploy/docker-compose.yml --project-directory . up --build Then in a browser trying to open either HTTP://localhost:8000 or HTTP://0.0.0.0:8000, neither seem to work for me.

s3rius commented 2 years ago

@writeson Please add -f ./deploy/docker-compose.dev.yml before project-directory.

Because by default docker compose config doesn't expose any ports.

s3rius commented 2 years ago

Please close the issues if the fix is confirmed.

writeson commented 2 years ago

The change you suggested, adding ./ in front of deploy/docker-compose.yml didn't fix the problem. However, adding:

ports:
  - 8000:8000

To the api service, and:

ports:
  - 3306:3306

To the db service, made HTTP://localhost/8000 return something, and the database visible to tools like DataGrip.

I am getting this message in the startup sequence though:

doug_fastapi-db-1   | find: '/docker-entrypoint-startdb.d/': No such file or directory

And HTTP://localhost:8000/health returns a 404

s3rius commented 2 years ago

@writeson Yeah. Adding ports in docker-compose will definitely solve the problem.

But I was suggesting you to try this command:

docker-compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml --project-directory . up --build

Because it overrides previous compose files.

Also, the correct URL for healthchecks is /api/health

You can check list of all URLs in swagger: /api/docs

writeson commented 2 years ago

Thanks for the full command; I'm still pretty much a noob at Docker. Also, what can I say about the /api/health and /api/docs aside from D'OH! I'm being particularly dense lately.

s3rius commented 2 years ago

It's totally ok. You'll learn everything soon. Also, by opening this issue, you may help someone who'll be struggling with the same problem as you. Every issue is super helpful. Thanks.

yashnerkar commented 11 months ago

where I can see the swagger UI, I have used the docker command you mentioned above. Also, I am new to this thing, can we have the documentation for this template? As we run a fast API app on localhost, is it compulsory to require the docker?

s3rius commented 11 months ago

You need to either set ports in you docker compose file, as mentioned here or find out container's IP and send request directly to it.

s3rius commented 11 months ago

Docker is not required, but it makes working with application easier, because you don't need to spin up the database on your local machine.