我运行了一个Flask应用程序gunicorn(在装有 Ubuntu 20.04 的 Dell latitude 5410 笔记本电脑上),我配置了Docker以按照本精彩指南中的建议运行它。
这是我的boot.sh:
#!/bin/sh
source venv/bin/activate
while true; do
flask db init
flask db migrate
flask db upgrade
if [[ "$?" == "0" ]]; then
break
fi
echo Deploy command failed, retrying in 5 secs...
sleep 5
done
exec gunicorn -b 0.0.0.0:5000 --access-logfile - --error-logfile - main:app
Run Code Online (Sandbox Code Playgroud)
并将Dockerfile其称为入口点:
FROM python:3.8-alpine
RUN adduser -D diagnosticator
RUN apk add --no-cache bash mariadb-dev mariadb-client python3-dev …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个用 Python Flask 编写的新应用程序,由 gunicorn 运行然后 dockerised。
我遇到的问题是 docker 容器内的性能非常差、不一致,我最终得到了响应,但我不明白为什么性能下降。有时我在日志中看到[CRITICAL] WORKER TIMEOUT (pid:9)。
这是我的应用程序:
服务器.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "The server is running!"
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
文件
FROM python:3.6.9-slim
# Copy all the files to the src folder
COPY build/ /usr/src/
# Create the virtual environment
RUN python3 -m venv /usr/src/myapp_venv
# Install the requirements
RUN /usr/src/myapp_venv/bin/pip3 install -r /usr/src/requirements.txt
# Runs gunicorn
# --chdir sets the directory where …Run Code Online (Sandbox Code Playgroud)