0

I am new to Docker and Docker-compose. I built dockerfile and docker-compose.yml to run my flask hello world. But after I change app.py, and docker-compose up, it didn't reflect my code changes.

Dockerfile:

FROM ubuntu:latest

RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential && \
    pip install flask PyMySQL pandas pymysql sqlalchemy

COPY . /app
WORKDIR /app

ENTRYPOINT ["python", "app.py"]

Docker-compose.yml:

version: '3'

services:
    web:
        build: ./web
        volumes:
          - .:/tmp
        ports:
          - "5000:5000"

Please help me. I just want my code changes automatically reflected.

Best

Peter Cui
  • 419
  • 1
  • 4
  • 8

2 Answers2

0

The COPY instruction copies file versions at the moment of building the image, ignoring subsequent file changes.

Source: https://stackoverflow.com/a/40276268/5649170

kinuax
  • 25
  • 8
0

Since you copy your code into docker image during its building:

COPY . /app

you need to re-build your docker image each time you update code and then run container from updated image.

If you would mount folder with your code to docker container - code will automatically updated in container thanks to mounting but you still need to restart your application to let python interpreter to load updated code into memory to start executing it. So that's not a solution due to manual work.

I would recommend to pay attention to some CI/CD platform, for example to Jenkins that will allow you to automate this process. And in this case you can just push your code to version control system and Jenkins will do all mentioned steps automatically so your application will be automatically updated and restarted.

Artsiom Praneuski
  • 2,259
  • 16
  • 24
  • So if you thinking about using Jenkins to solve your problem - I would recommend this course: https://www.udemy.com/learn-devops-ci-cd-with-jenkins-using-pipelines-and-docker – Artsiom Praneuski Feb 25 '18 at 16:17