Unable to deploy dockerized FastAPI application to ECS fargate
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
Dockerfile:
# Image from dockerhub
FROM python:3.8.1-slim
ENV PYTHONUNBUFFERED 1
# Expose the port 8000 in which our application runs
EXPOSE 8000
# Make /app as a working directory in the container
WORKDIR /app
# Copy requirements from host, to docker container in /app
COPY ./requirements.txt .
# Copy everything from ./app directory to /app in the container
COPY ./app .
# Install the dependencies
RUN pip install --no-deps -r requirements.txt
# Run the application in the port 8000
ENTRYPOINT [ "uvicorn" ]
CMD ["--host", "0.0.0.0", "--port", "8000", "app.main:app"]
docker-compose.yml
version: '3.8'
services:
web:
restart: always
build:
context: .
dockerfile: ./Dockerfile
volumes:
- .:/app
ports:
- 8000:8000
Description
docker-compose and docker build both work locally on Docker Desktop. However, when I deploy to ECS/fargate, I get the following error.
### Cloudwatch logs for ECS/Fargate Task
Traceback (most recent call last):
File “/usr/local/bin/uvicorn”, line 8, in <module> sys.exit(main()) File “/usr/local/lib/python3.8/site-packages/click/core.py”, line 829, in call return self.main(*args, **kwargs) File “/usr/local/lib/python3.8/site-packages/click/core.py”, line 782, in main rv = self.invoke(ctx) File “/usr/local/lib/python3.8/site-packages/click/core.py”, line 1066, in invoke return ctx.invoke(self.callback, **ctx.params) File “/usr/local/lib/python3.8/site-packages/click/core.py”, line 610, in invoke return callback(*args, **kwargs) File “/usr/local/lib/python3.8/site-packages/uvicorn/main.py”, line 362, in main run(**kwargs) File “/usr/local/lib/python3.8/site-packages/uvicorn/main.py”, line 386, in run server.run() File “/usr/local/lib/python3.8/site-packages/uvicorn/server.py”, line 49, in run loop.run_until_complete(self.serve(sockets=sockets)) File “uvloop/loop.pyx”, line 1494, in uvloop.loop.Loop.run_until_complete File “/usr/local/lib/python3.8/site-packages/uvicorn/server.py”, line 56, in serve config.load() File “/usr/local/lib/python3.8/site-packages/uvicorn/config.py”, line 308, in load self.loaded_app = import_from_string(self.app) File “/usr/local/lib/python3.8/site-packages/uvicorn/importer.py”, line 23, in import_from_string raise exc from None File “/usr/local/lib/python3.8/site-packages/uvicorn/importer.py”, line 20, in import_from_string module = importlib.import_module(module_str) File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “<frozen importlib._bootstrap>”, line 1014, in _gcd_import File “<frozen importlib._bootstrap>”, line 991, in _find_and_load File “<frozen importlib._bootstrap>”, line 961, in _find_and_load_unlocked File “<frozen importlib._bootstrap>”, line 219, in _call_with_frames_removed File “<frozen importlib._bootstrap>”, line 1014, in _gcd_import File “<frozen importlib._bootstrap>”, line 991, in _find_and_load File “<frozen importlib._bootstrap>”, line 973, in _find_and_load_unlocked ModuleNotFoundError: No module named ‘uvicorn app’
Operating System
Linux
Operating System Details
docker
FastAPI Version
0.65.2
Python Version
3.8.1
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9
Top GitHub Comments
Hello @schrecka, were you able to deploy it? I have many issues too
Hi @schrecka I am confused by the error text itself:
Is it a good practice to use entrypoint command like this? Usually I do not use
ENTRYPOINT
for binary files.Would it work if you will run application as it mentioned in FastAPI docs? The example provided for RaspberryPI, but mentioned
CMD
command is valid for any platform.Sorry if i missed something