简体   繁体   中英

Avoid contantly rebuild docker image

I'm building an app using Docker. My Dockerfile looks like this:

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 . The thing is, python-igraph is stuck on this part

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 was "readding" new files and because of docker layers, when first layer changes, all the next have to be rebuilt. Now, my Dockerfile looks like this:

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. I'm going to leave this here anyhow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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