Re:Alpine makes Python Docker builds slower, and images larger
by je42 on Wednesday January 29, 2020 @03:59PM
(#22185745)
alternatively you can create a multi staged build.
also you dont need clean up the builder, since the unused files are not used in the final image.
also add a new file you can just append it to the builder. (not rebuild required of the previous installs required since you don't care about the size of the builder image )
FROM python:3.8-alpine as builder
RUN apk add --virtual build-dependencies gcc build-base freetype-dev libpng-dev openblas-dev
RUN pip install matplotlib pandas
FROM python:3.8-alpine
# a couple of copy commands to copy binaries and py files from builder to the final image.
COPY --from=builder /usr/bin /usr/bin
COPY --from=builder /usr/local/lib/ /usr/local/lib/
also you dont need clean up the builder, since the unused files are not used in the final image.
also add a new file you can just append it to the builder. (not rebuild required of the previous installs required since you don't care about the size of the builder image )