search

Home  >  Q&A  >  body text

flask - 为什么每次当我workdir所对应的文件的内容发生变化,要重新build images,然后生成container才会生效

dockerfile没有改变,只是workdir所对应的容器外部的文件发生了改变

  1. 请问这是必须的么,如果是这样的话,是要用docker compose-up 自动简化这个过程?

  2. 如果不是必须的话,因为我的dockerfile的问题么?
    dockerfile如下:

    FROM ubuntu
    MAINTAINER Tarty.Phoenix <tartyphoenix@gmail.com>
    RUN apt-get update
    RUN apt-get install -y -q python-all python-pip libffi-dev
    RUN apt-get install -y -q python-dev build-essential
    ADD ./flask_pure/requirements.txt /tmp/requirements.txt
    RUN pip install -qr /tmp/requirements.txt
    
    ADD ./flask_pure /opt/flask_pure/
    WORKDIR /opt/flask_pure
    
    EXPOSE 80
    CMD ["python", "manage.py", "runserver"]
大家讲道理大家讲道理2775 days ago541

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-04-24 09:12:59

    1. First of all, the directory represented by workdir is the directory in the container, not the host.

    2. The following content changes require rebuilding the image

      • Dockerfile itself changes

      • Source file changes for COPY / ADD instructions

    3. docker-compose supports re-building the image during operation

      service:
          - build: <image_base_dir>

    reply
    0
  • 怪我咯

    怪我咯2017-04-24 09:12:59

    There is one point in your question that I need to explain to you.
    After creating and editing the dockerfile, build creates an image (mirror), and then runs an image to generate a container (container). Then the image and container have a one-to-one correspondence. Then when you edit the dockerfile and change the workdir, the container you create will of course enter the new workdir by default. Therefore, the title of your question should not describe a question, but a correct logical description.

    reply
    0
  • 迷茫

    迷茫2017-04-24 09:12:59

    Your understanding of docker is wrong. What you do is just packaging the contents of a certain folder into an image.
    It is recommended that you understand the concept of VOLUME volume in docker. Only by specifying the -v parameter when starting the container or specifying the VOLUME parameter in docker-compose.yml can the container mount the local directory.

    So how to distinguish whether the container needs to be mounted to the local directory? My understanding is whether it is in development status or production status.
    If you are in a development state and the code needs to change frequently, it is difficult to accept that every time the code is modified, it needs to be repackaged into the image.
    If you are in production, imagine that there are so many images on Docker Hub. If these images provide you with an installation environment and source code, then you need to manually specify the VOLUME to mount the source code directory, and then start the container. I will compile and install it. What do you think of this experience?

    reply
    0
  • Cancelreply