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

666
Views
is there a difference between running fastapi from uvicorn command in dockerfile and from pythonfile?

I am running a fast api and when i was developing i had the following piece of code in my app.py file

code in app.py:

import uvicorn


if __name__=="__main__":
    uvicorn.run("app.app:app",host='0.0.0.0', port=4557, reload=True, debug=True, workers=3)

so i was about to run CMD ["python3","app.py"] in my Dockerfile.

on the fastapi example they did something like this :

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]

I want to know what is the difference between these two methods as i think both of them will work.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No, there is no difference.

The commadline run method (uvicorn app.main:app) and executing the app.py using python command (python app.py) are the same. Both methods are calling the uvicorn.main.run(...) function under the hood.

In other words, the uvicorn command is a shortcut to the uvicorn.run(...) function.

So, in your case the function call

uvicorn.run("app.app:app",host='0.0.0.0', port=4557, reload=True, debug=True, workers=3)

can be done by uvicorn commandline as,

uvicorn app.app:app --host 0.0.0.0 --port 4557 --reload --debug --workers 3

Side Notes

The --debug option is hidden from the command line options help page, but it can be found in the source code. Thus, it feels running the app using uvicorn command can be considered as a production thing.

over 4 years ago · Santiago Trujillo Report

0

The answer is no. There will be no difference in app, deploying with Docker just making it easier, without Docker you need to run it with ASGI compatible server like Uvicorn, also you might want to set up some tooling to make sure it is restarted automatically if it stops or crashes. Instead of trying to handle it manually, a Docker image can handle all these jobs automatically.

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!