title: How to run FastAPI app on multiple ports?
body: <p>I have a FastAPI application that I am running on port 30000 using Uvicorn programmatically. Now I want to run the same application on port 8443 too. The same application needs to run on both these ports. How can I do this within the Python code?</p>
  <p>Minimum Reproducible code:</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import FastAPI
  import uvicorn
  
  app = FastAPI()
  
  
  @app.get(&quot;/healthcheck/&quot;)
  def healthcheck():
      return 'Health - OK'
  
  if __name__ == &quot;__main__&quot;:
      uvicorn.run(app, host=&quot;0.0.0.0&quot;, port=30000)
  </code></pre>
  <p>I want to something like</p>
  <pre class="lang-py prettyprint-override"><code>if __name__ == &quot;__main__&quot;:
      uvicorn.run(app, host=&quot;0.0.0.0&quot;, ports=[30000,8443])
  </code></pre>
  <p>Explanation:
  My application will be running on my organizations Azure Kubernetes Service. Apps running on port 30000 are reserved for Internal HTTP traffic and apps running on 8443 are mapped to 443 of Kubernetes Service to be exposed to external traffic.</p>
  <p>Further Details:
  I will be creating a Docker Container out of this application and the idea is to include</p>
  <pre class="lang-sh prettyprint-override"><code>CMD [&quot;python3&quot;, &quot;app.py&quot;]
  </code></pre>
  <p>at the end to run the application. I am looking for a solution that would either provide a way to change the python code ( <code>uvicorn.run(app, host=&quot;0.0.0.0&quot;, ports=[30000,8443])</code> ) or a change to the CMD command in the Dockerfile like <a href="https://github.com/encode/uvicorn/issues/571#issuecomment-830163848" rel="nofollow noreferrer">This GitHub Issue Comment</a> - <code>gunicorn -k uvicorn.workers.UvicornWorker -w 1 --bind ip1:port1 --bind ip2:port2 --bind ip3:port3 </code></p>