简体   繁体   English

Dockerize我的烧瓶应用程序

[英]Dockerize my flask app

I am new to Docker and Docker-compose. 我是Docker和Docker-compose的新手。 I built dockerfile and docker-compose.yml to run my flask hello world. 我构建了dockerfile和docker-compose.yml来运行我的烧瓶你好世界。 But after I change app.py, and docker-compose up, it didn't reflect my code changes. 但是在我更改app.py和docker-compose之后,它并没有反映我的代码更改。

Dockerfile: 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: 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. COPY指令在构建映像时复制文件版本,而忽略随后的文件更改。

Source: https://stackoverflow.com/a/40276268/5649170 资料来源: https : //stackoverflow.com/a/40276268/5649170

Since you copy your code into docker image during its building: 由于您在构建过程中将代码复制到docker映像中,因此:

COPY . /app

you need to re-build your docker image each time you update code and then run container from updated image. 您需要在每次更新代码时重新构建docker映像,然后从更新的映像运行容器。

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. 如果您将带有代码的文件夹安装到docker容器中-由于进行了安装,代码将在容器中自动更新,但是您仍然需要重新启动应用程序以让python解释器将更新后的代码加载到内存中以开始执行它。 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. 我建议您注意某些CI / CD平台,例如Jenkins ,它可以使您自动执行此过程。 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. 在这种情况下,您只需将代码推送到版本控制系统,Jenkins就会自动执行所有上述步骤,因此您的应用程序将自动更新并重新启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM