首页 > 开发 > 云计算 > 正文

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

2017-09-12 09:51:59  来源: 网友分享

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

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

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

    FROM ubuntuMAINTAINER Tarty.Phoenix <tartyphoenix@gmail.com>RUN apt-get updateRUN apt-get install -y -q python-all python-pip libffi-devRUN apt-get install -y -q python-dev build-essentialADD ./flask_pure/requirements.txt /tmp/requirements.txtRUN pip install -qr /tmp/requirements.txtADD ./flask_pure /opt/flask_pure/WORKDIR /opt/flask_pureEXPOSE 80CMD ["python", "manage.py", "runserver"]

解决方案

  1. 首先 workdir 代表的目录是容器里面的目录,不是 host 的。

  2. 下面的内容变化需要重新 build image

    • dockerfile 本身变化

    • COPY / ADD 指令的 source 文件变化

  3. docker-compose 支持运行的时候重新 build image 的

    service:    - build: <image_base_dir>