I have added fastapi to a docker container which does background tasks using BackgroundTask from fastapi. When i run the container the page is not loading and i have seen this error in docker desktop logs gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>. I am using docker run -d --name mycontainer -p 8080:8080 onetest to run the container.
entrypoint.sh
#!/bin/bash
gunicorn --worker-tmp-dir /dev/shm --config gunicorn.config.py app.main:app
docker file
FROM python:3.9-slim
COPY ./requirements.txt ./requirements.txt
RUN pip3 install --no-cache-dir --upgrade -r ./requirements.txt
COPY ./app ./app
COPY ./inputs ./inputs
COPY ./model ./model
COPY ./tests ./tests
COPY ./gunicorn.config.py ./gunicorn.config.py
COPY ./Procfile ./Procfile
COPY entrypoint.sh .
EXPOSE 8080
RUN chmod +x entrypoint.sh
CMD [ "./entrypoint.sh" ]
docker_config.py
bind = "0.0.0.0:8080"
workers = 4
timeout = 300
# Using Uvicorn's Gunicorn worker class
worker_class = "uvicorn.workers.UvicornWorker"