• <i id='pOv3f'><tr id='pOv3f'><dt id='pOv3f'><q id='pOv3f'><span id='pOv3f'><b id='pOv3f'><form id='pOv3f'><ins id='pOv3f'></ins><ul id='pOv3f'></ul><sub id='pOv3f'></sub></form><legend id='pOv3f'></legend><bdo id='pOv3f'><pre id='pOv3f'><center id='pOv3f'></center></pre></bdo></b><th id='pOv3f'></th></span></q></dt></tr></i><div id='pOv3f'><tfoot id='pOv3f'></tfoot><dl id='pOv3f'><fieldset id='pOv3f'></fieldset></dl></div>
  • <legend id='pOv3f'><style id='pOv3f'><dir id='pOv3f'><q id='pOv3f'></q></dir></style></legend>

    1. <tfoot id='pOv3f'></tfoot>
      • <bdo id='pOv3f'></bdo><ul id='pOv3f'></ul>

      1. <small id='pOv3f'></small><noframes id='pOv3f'>

        Docker如何仅在发生更改时运行pip requirements.txt?

        时间:2023-09-10
          • <i id='tGsMH'><tr id='tGsMH'><dt id='tGsMH'><q id='tGsMH'><span id='tGsMH'><b id='tGsMH'><form id='tGsMH'><ins id='tGsMH'></ins><ul id='tGsMH'></ul><sub id='tGsMH'></sub></form><legend id='tGsMH'></legend><bdo id='tGsMH'><pre id='tGsMH'><center id='tGsMH'></center></pre></bdo></b><th id='tGsMH'></th></span></q></dt></tr></i><div id='tGsMH'><tfoot id='tGsMH'></tfoot><dl id='tGsMH'><fieldset id='tGsMH'></fieldset></dl></div>

            <small id='tGsMH'></small><noframes id='tGsMH'>

                <bdo id='tGsMH'></bdo><ul id='tGsMH'></ul>
                  <tbody id='tGsMH'></tbody>
                <tfoot id='tGsMH'></tfoot>

                1. <legend id='tGsMH'><style id='tGsMH'><dir id='tGsMH'><q id='tGsMH'></q></dir></style></legend>
                  本文介绍了Docker如何仅在发生更改时运行pip requirements.txt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Dockerfile 中,我有一个安装 requirements.txt 的层:

                  In a Dockerfile I have a layer which installs requirements.txt:

                  FROM python:2.7
                  RUN pip install -r requirements.txt
                  

                  当我构建 docker 映像时,它会运行整个过程不管对此文件所做的任何更改.

                  When I build the docker image it runs the whole process regardless of any changes made to this file.

                  如果文件发生更改,我如何确保 Docker 仅运行 pip install -r requirements.txt?

                  How do I make sure Docker only runs pip install -r requirements.txt if there has been a change to the file?

                  Removing intermediate container f98c845d0f05
                  Step 3 : RUN pip install -r requirements.txt
                   ---> Running in 8ceb63abaef6
                  Collecting https://github.com/tomchristie/django-rest-framework/archive/master.zip (from -r requirements.txt (line 30))
                    Downloading https://github.com/tomchristie/django-rest-framework/archive/master.zip
                  Collecting Django==1.8.7 (from -r requirements.txt (line 1))
                  

                  推荐答案

                  我假设在构建过程中的某个时刻,您将使用 COPY 将整个应用程序复制到 Docker 映像中或 添加:

                  I'm assuming that at some point in your build process, you're copying your entire application into the Docker image with COPY or ADD:

                  COPY . /opt/app
                  WORKDIR /opt/app
                  RUN pip install -r requirements.txt
                  

                  问题在于,每次将整个应用程序复制到映像中时,都会使 Docker 构建缓存失效.这也会使所有后续构建步骤的缓存失效.

                  The problem is that you're invalidating the Docker build cache every time you're copying the entire application into the image. This will also invalidate the cache for all subsequent build steps.

                  为防止这种情况,我建议在将整个应用程序添加到映像之前,在单独的构建步骤中仅复制 requirements.txt 文件:

                  To prevent this, I'd suggest copying only the requirements.txt file in a separate build step before adding the entire application into the image:

                  COPY requirements.txt /opt/app/requirements.txt
                  WORKDIR /opt/app
                  RUN pip install -r requirements.txt
                  COPY . /opt/app
                  # continue as before...
                  

                  由于需求文件本身可能很少更改,因此您将能够使用缓存层,直到您将应用程序代码添加到图像中.

                  As the requirements file itself probably changes only rarely, you'll be able to use the cached layers up until the point that you add your application code into the image.

                  这篇关于Docker如何仅在发生更改时运行pip requirements.txt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 docker 中部署一个最小的烧瓶应用程序 - 服务器 下一篇:standard_init_linux.go:211: exec 用户进程导致“exec 格式

                  相关文章

                  最新文章

                  <legend id='oUsmZ'><style id='oUsmZ'><dir id='oUsmZ'><q id='oUsmZ'></q></dir></style></legend>

                  <small id='oUsmZ'></small><noframes id='oUsmZ'>

                2. <i id='oUsmZ'><tr id='oUsmZ'><dt id='oUsmZ'><q id='oUsmZ'><span id='oUsmZ'><b id='oUsmZ'><form id='oUsmZ'><ins id='oUsmZ'></ins><ul id='oUsmZ'></ul><sub id='oUsmZ'></sub></form><legend id='oUsmZ'></legend><bdo id='oUsmZ'><pre id='oUsmZ'><center id='oUsmZ'></center></pre></bdo></b><th id='oUsmZ'></th></span></q></dt></tr></i><div id='oUsmZ'><tfoot id='oUsmZ'></tfoot><dl id='oUsmZ'><fieldset id='oUsmZ'></fieldset></dl></div>

                    <tfoot id='oUsmZ'></tfoot>
                      <bdo id='oUsmZ'></bdo><ul id='oUsmZ'></ul>