I am working on a Flask project which I used to run locally before in debug mode with the simple flask run command.
Now, I have to switch to a Docker environment. I am new to Docker. I have installed Docker Desktop for my Windows machine.
The commands I use to run my project locally are: docker-compose build and docker-compose up. As you may expect, the build takes a long time.
Now, when I make changes, the project doesn't reflect my recent changes without a new build. What should I do to have a live demo for debugging like local Flask deployment gave me?
This is my DOCKERFILE:
FROM python:3.12
WORKDIR /app
RUN apt-get -y update && apt-get install -y curl gnupg
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get -y update && ACCEPT_EULA=Y apt-get install -y msodbcsql18
RUN apt-get install -y \
wkhtmltopdf \
xvfb \
libfontconfig \
libxrender1 \
libjpeg62-turbo
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "run.py"]
I read that 'Bind Mounts' could help in this in some way but the documentation doesn't really shed much light on my use case.
My run.py file:
import os
from app import app, db
with app.app_context():
db.create_all() # Create defined SQL DB Tables
if __name__ == '__main__':
if os.name == 'nt':
app.run(host='0.0.0.0', port=5000, debug=True, ssl_context=('xyz.crt', 'xyz.key'))
else:
import subprocess
cmd = ['gunicorn', '-w', '1', '--threads', '10', '-b', '0.0.0.0:5000', '--certfile', 'xyz.crt', '--keyfile', 'xyz.key', '--timeout', '300', 'app:app']
subprocess.call(cmd)
run.py. Are you familiar with this: flask.palletsprojects.com/en/stable/quickstart/#debug-moderun.pyand am familiar with debug moderun.py. Docker doesn't run directly on Windows - the desktop app installs a linux VM and redirects commands to that.