简体   繁体   English

避免不断重建Docker映像

[英]Avoid contantly rebuild docker image

I'm building an app using Docker. 我正在使用Docker构建应用程序。 My Dockerfile looks like this: 我的Dockerfile看起来像这样:

FROM python:3.7.0
WORKDIR /app
COPY . /app
RUN apt-get -y update && apt-get -y install apt-utils build-essential libxml2-dev zlib1g-dev python-dev python-pip pkg-config libffi-dev libcairo-dev
RUN pip install -r requirements.txt
CMD ["./run"]

My project structure: 我的项目结构:

.
├── Dockerfile
├── requirements.txt
├── run
└── src
    ├── stuff

In requirements, I put plotly , pytest and python-igraph . 在需求中,我放置了plotlypytestpython-igraph The thing is, python-igraph is stuck on this part 事实是, python-igraph卡在这部分上

Running setup.py bdist_wheel for python-igraph: started
Running setup.py bdist_wheel for python-igraph: still running...

for a pretty damn long time but in the end it pulls the data and the image is built. 在相当长的一段时间内,但最终它会拉取数据并生成图像。 However, it's unacceptable to rebuild the project every time for that long. 但是,如此长时间每次重建项目都是不可接受的。

What would be the correct approach to somehow extract the modules that aren't dependent on each other? 提取彼此不依赖的模块的正确方法是什么?

When I was writing the last sentence, I got the idea what's going on. 当我写最后一句话时,我知道发生了什么。 Every time I rebuilt the app, COPY . /app 每次我重建应用程序时,请COPY . /app COPY . /app was "readding" new files and because of docker layers, when first layer changes, all the next have to be rebuilt. COPY . /app正在“读取”新文件,并且由于docker层,当第一层发生更改时,所有下一个都必须重建。 Now, my Dockerfile looks like this: 现在,我的Dockerfile看起来像这样:

FROM python:3.7.0
RUN apt-get -y update && apt-get -y install apt-utils build-essential libxml2-dev zlib1g-dev python-dev python-pip pkg-config libffi-dev libcairo-dev
WORKDIR /app
COPY requirements.txt /app
RUN pip install -r requirements.txt
COPY . /app
CMD ["./run"]

The need to download python-igraph every time is gone. 每次都不需要下载python-igraph I'm going to leave this here anyhow. 无论如何,我要离开这里。

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

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