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
The COPY
instruction copies file versions at the moment of building the image, ignoring subsequent file changes.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.