I have a Flask application that I run through gunicorn
(on a Dell latitude 5410 laptop with Ubuntu 20.04) and I configured the Docker to run it as suggested in this wonderful guide.
Here is my 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
and the Dockerfile
just call it as entrypoint:
FROM python:3.8-alpine
RUN adduser -D diagnosticator
RUN apk add --no-cache bash mariadb-dev mariadb-client python3-dev build-base libffi-dev openssl-dev
WORKDIR /home/diagnosticator
COPY requirements.txt requirements.txt
RUN python -m venv venv
RUN venv/bin/pip install -U pip
RUN venv/bin/pip install wheel
RUN venv/bin/pip install -r requirements.txt
RUN venv/bin/pip install gunicorn pymysql
COPY app app
COPY upload upload
COPY variant_dependencies variant_dependencies
COPY main.py config.py boot.sh ./
COPY convert_VCF_REDIS.py asilo_variant_functions.py cloud_bigtable_functions.py mongodb_functions.py redis_functions.py ./
COPY docker_functions.py ./
RUN chmod a+x boot.sh
ENV FLASK_APP main.py
RUN chown -R diagnosticator:diagnosticator ./
USER diagnosticator
EXPOSE 5000
ENTRYPOINT ["./boot.sh"]
I run the Docker in a docker-network
with:
docker network create --driver bridge diagnosticator-net
The problem I noticed is that the Docker container for some reason hangs after a bit of inactivity with gunicorn
error:
[CRITICAL] WORKER TIMEOUT
here the docker logs:
192.168.32.1 - - [12/Jun/2021:12:28:30 +0000] "GET /patient_page/GHARIgANY21uuITW2196372 HTTP/1.1" 200 19198 "http://127.0.0.1:3000/patient_result" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
[2021-06-12 12:29:10 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:16)
[2021-06-12 12:29:10 +0000] [16] [INFO] Worker exiting (pid: 16)
[2021-06-12 12:29:10 +0000] [17] [INFO] Booting worker with pid: 17
[2021-06-12 12:29:10,905] INFO in __init__: Diagnosticator-local startup
[2021-06-12 12:29:41 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:17)
20
[2021-06-12 12:29:41 +0000] [17] [INFO] Worker exiting (pid: 17)
[2021-06-12 12:29:41 +0000] [18] [INFO] Booting worker with pid: 18
[2021-06-12 12:29:42,094] INFO in __init__: Diagnosticator-local startup
[2021-06-12 12:30:12 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:18)
[2021-06-12 12:30:12 +0000] [18] [INFO] Worker exiting (pid: 18)
and the application just hangs loading forever any page you try to access.
I've seen some suggestions here and googling it, like this one or this one, suggesting to work on gunicorn --timeout
but the problem keeps happening no matter what I put there.
Any help will be deeply appreciated cause I cannot figure out any real solution!