Cache PIP packages in dockerfile
I am trying to setup docker for my python project, Which uses virtual environment and has defined some dependencies in
I have setup
docker-compose too which uses
Dockerfile to build my project image using command
docker-compose up --build
FROM ubuntu:16.04 FROM python:3.5 MAINTAINER **** ADD . /core-proejct WORKDIR /core-project RUN pip3 install virtualenv RUN . /bin/activate RUN pip install -r requirements.txt
So, every time when I am trying to build the image its installing all pip modules from
Is there anyway by which I can cache the pip modules and use the cached version while building image.
One Solution collect form web for “Cache PIP packages in dockerfile”
First things first, the
FROM ubuntu:16.04 in your dockerfile is redundant as a single image can only have one upstream.
The simple way to solve your problem is move your
pip commands to before you add your project, so that changing your project doesn’t invalidate the whole cache.
Lastly, you really don’t need to use virtualenv in a container, otherwise you may be doing something wrong.
FROM python:3.5 # MAINTAINER is deprecated. Use LABEL instead. LABEL maintainer "your info here" WORKDIR /core-project ADD ./requirements.txt . RUN pip install -r requirements.txt # Add everything else now. ADD . .