Issue
I have a Dockerfile which starts with the following:
FROM python:3.7-slim
RUN apt-get update && apt-get install build-essential -y
Problem is, this layer is always changing, so when I run docker build -t <mytag> .
, this layer (and subsequent ones) run again, which takes up significant time.
Is there a way to install build-essential
in my Dockerfile in a layer which doesn't constantly change?
EDIT: I had a COPY line before RUN, which I removed from the question as I didn't want to include the names of private files, but it didn't occur to me that that was what was making the build re-run from this step.
Solution
Create a base image which contains:
FROM python:3.7-slim
RUN apt-get update && apt-get install build-essential -y
Build it:
docker build -t mybase .
Then use it for new images:
FROM mybase
Answered By - LinPy Answer Checked By - Pedro (WPSolving Volunteer)