Distroless-python3是瘦身容器,只能运行python程序,所以无法直接运行gunicorn
gunicorn是通过pip安装上的,所以可以在只有python环境容器中运行
首先要找到gunicorn的运行路径:
查看gunicorn的文件信息:
发现实质是运行python程序,所以可以对其进行稍作调整,如下:
run_gunicorn.py:
#!/venv/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from gunicorn.app.wsgiapp import run
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run())
将其复制在项目中,然后在Dockerfile里面写入如下命令即可:
FROM gcr.io/distroless/python3-debian10
COPY --from=build-venv /venv /venv
COPY . /project
WORKDIR /project
ENTRYPOINT ["/venv/bin/python3", "run_gunicorn.py","--bind=0.0.0.0:8888","--workers=1","--pythonpath=app", "app.wsgi","--timeout","300"]