I am trying to run a simple FastAPI docker container. My only requirement is that I need the redis module.
Here is my Dockerfile
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
COPY ./app /app
CMD pip install -r /app/infrastructure_req.txt
According to the log, the pip install was successful
Collecting redis==3.5.3
Downloading redis-3.5.3-py2.py3-none-any.whl (72 kB)
Installing collected packages: redis
Successfully installed redis-3.5.3
WARNING: You are using pip version 20.0.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Requirement already satisfied: redis==3.5.3 in /usr/local/lib/python3.8/site-packages (from -r
/app/infrastructure_req.txt (line 1)) (3.5.3)
WARNING: You are using pip version 20.0.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Requirement already satisfied: redis==3.5.3 in /usr/local/lib/python3.8/site-packages (from -r
/app/infrastructure_req.txt (line 1)) (3.5.3)
WARNING: You are using pip version 20.0.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
However, the docker container quits immediately after the CMD.
if I attempt to build the image without the pip install, I get this error instead
# Let the DB start
sleep 10;
# Run migrations
alembic upgrade head
[2020-10-01 19:08:24 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-10-01 19:08:24 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-10-01 19:08:24 +0000] [1] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-10-01 19:08:24 +0000] [7] [INFO] Booting worker with pid: 7
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120,
"keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null,
"host": "0.0.0.0", "port": "80"}
[2020-10-01 19:08:25 +0000] [1] [INFO] Shutting down: Master
[2020-10-01 19:08:25 +0000] [1] [INFO] Reason: Worker failed to boot.
{"loglevel": "info", "workers": 2, "bind": "0.0.0.0:80", "graceful_timeout": 120, "timeout": 120,
"keepalive": 5, "errorlog": "-", "accesslog": "-", "workers_per_core": 1.0, "use_max_workers": null,
"host": "0.0.0.0", "port": "80"}
I am unclear what to do to resolve this.
Check your dockerfile. The last command you issue is the
pipinstallation. The installation works and since following there is no other command, it simply shuts down.The dockerfile should look as follows