Symptom
It seems to be failing due to something related to DNS... This issue occurs in a container environment but not in a local environment.
$ docker container run fastapi
...
ERROR: [Errno -2] Name or service not known
...
$
Solution
Specify --host 0.0.0.0
, as the default for uvicorn is 127.0.0.1
CMD [ "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000" ]
Additional Information
In my case, I was using environment variables, so I needed to modify it further like this:
CMD ["sh", "-c", "uvicorn app:app --host ${HOST} --port 8000"]