Distroless running gunicorn in a thin container

Distroless running gunicorn in a thin container

Distroless-python3 is a slim container, which can only run python programs, so gunicorn cannot be run directly

gunicorn is installed through pip, so it can be run in a python-only environment container

1. find the running path of gunicorn:

View Image

View gunicorn file information:

 View Image

It is found that the essence is to run the python program, so it can be slightly adjusted as follows:


#!/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())

Copy it in the project, and then write the following command in the 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=","--workers=1","--pythonpath=app", "app.wsgi","--timeout","300"]


Reference : https://blog.csdn.net/u014595589/article/details/107127322