I am trying to deploy my FastAPI app to a docker container (P.S. I am a beginner in using docker). I used the below code. Without the DB, this code is working fine in the docker container. However, when I try to try to connect to DB, the path "URL:port/" is showing connection refused. I used the exact steps as mentioned in uvicorn-gunicorn-fastapi-docker
from fastapi import FastAPI
from pymongo import MongoClient
app = FastAPI()
client = MongoClient('localhost', port=27017)
db = client.safetypointer
@app.get("/")
def read_root():
all_users = db.users.find({}, {"_id":0})
return {"Hello": "World" , "allUsers": all_users}