Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

695
Views
Fast API app to docker container connection refused

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}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Local host should likely be replaced with the name of your mongo container. I would also recommend taking a look at docker-composer as it can make deploying two connected containers easier.

Here is a link to an example with flask it would be similar with fastapi: awesome-compose

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!