0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Can't Start with FastAPI, Docker, and Uvicorn...

Last updated at Posted at 2023-12-18

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"]
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?