Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multi-stage Dockerfiles with perl and perl-slim

The benefits of using multi-stage Docker builds is well-known. Using multi-stage builds with a pure Perl setup is trivial -- all it involves is copying the /usr/local/lib/perl5 directory:

FROM perl:5.28 as builder
COPY cpanfile cpanfile
RUN cpanm --installdeps .

FROM perl:5.28-slim
COPY --from=builder /usr/local/lib/perl5 /usr/local/lib/perl5
# Do other work here

You can also copy all of /usr/local/. Either way, this is a great way to cut down image size. I was able to reduce the size of an image from almost a gigabyte to some 200MB.

If you're dealing with some compiled dependencies, then this process probably isn't so simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment