-1

As the title states, I am working with a dockerized Flask app with Gunicorn, but the hot reload is not working.

I know I have to map the local file system to that of the container, so that it is aware of the changes and Flask on Debug mode will do the rest.

This is the structure of my project: enter image description here

This is my Dockerfile:

FROM python:3.9

ARG USER
ARG PASS
ARG RESOLVER_URL

ENV PIP_INDEX_URL=https://$USER:$PASS@$RESOLVER_URL
ENV FLASK_APP jfrog_api.py
ENV FLASK_ENV development

COPY . /app/
WORKDIR /app
RUN adduser --system --group app -u 1001 \
    && apt-get update \
    && apt-get upgrade -y \
    && python3 -m pip install -r requirements.txt
USER app:app

EXPOSE 5000

CMD ["gunicorn", "-b", "0.0.0.0:5000", "jfrog_api:app"]

This is my docker-compose.yml file:

version: '3'
services:
  jfrog-api:
    build: .
    image: jfrog-api
    ports:
      - "${JFROG_API_PORT:-5000}:5000"
    volumes:
      - type: volume
        source: data
        target: /data
    env_file: .env
    restart: always
volumes:
  data:

This is the entrypoint of my Flask application, jfrog_api.py:

from api import create_app

app = create_app()

I have checked many other similar cases but I still cannot make it work in my project. Any ideas would be greatly appreciated.

Xar
  • 7,572
  • 19
  • 56
  • 80
  • Docker is designed so that a container's code is isolated from anything on your host. Would a non-Docker Python virtual environment work better for this use case? – David Maze Jun 28 '22 at 13:20

1 Answers1

0

This answer should help provide context, but the TL;DR is that the Flask debugger doesn't work inside of Gunicorn.

Shy
  • 76
  • 1
  • 3