How do I hot-load a dockerized python app?

Viewed 354

I am unable to get hot reload work for my python app. I did try other threads Auto reloading flask server on Docker too. Here's my code:

#docker-compose.yml
app:
  build: .
  command: python -u app.py
  ports:
    - "5000:5000"
  volumes:
    - .:/app
  links:
    - db
db:
  image: mongo:latest
  hostname: dstudio_mongodb
  environment:
    - MONGO_INITDB_DATABASE=dstudio_db
  ports:
    - 27017:27017

My docker file

FROM python:3.7
ADD . /app
WORKDIR /app
RUN pip install -r requirements.txt

I am using docker-compose up for now.

1 Answers

Try to switch the ADD and WORKDIR statements, use * instead of .. Also, delete the command statement in the docker-compose and add CMD python -u app.py to your Dockerfile.

Dockerfile:

FROM python:3.7
WORKDIR /app
ADD * /app
RUN pip install -r requirements.txt
CMD python -u app.py

docker-compose.yml

version: "3.7"
app:
  build: .
  ports:
    - "5000:5000"
  volumes:
    - .:/app
  links:
    - db
db:
  image: mongo:latest
  hostname: dstudio_mongodb
  environment:
    - MONGO_INITDB_DATABASE=dstudio_db
  ports:
    - 27017:27017

Related