【发布时间】:2020-10-01 19:22:31
【问题描述】:
我正在尝试运行一个简单的 FastAPI docker 容器。我唯一的要求是我需要 redis 模块。
这是我的 Dockerfile
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8
COPY ./app /app
CMD pip install -r /app/infrastructure_req.txt
根据日志,pip安装成功
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.
但是,docker 容器在 CMD 之后立即退出。
如果我尝试在没有安装 pip 的情况下构建映像,则会收到此错误
# 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,
“主机”:“0.0.0.0”,“端口”:“80”}
我不清楚如何解决这个问题。
【问题讨论】:
-
其实
CMD的定义是容器完成后立即退出。您的意思是将RUN pip install作为您的映像构建的一部分吗? -
我用 RUN 替换了 CMD,它仍然在我的原始帖子底部给出了错误列表。
标签: python-3.x docker fastapi