Skip to content

Instantly share code, notes, and snippets.

@natanlao
Created August 8, 2020 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natanlao/fc8923ca5ef326f36cd580d457a2e411 to your computer and use it in GitHub Desktop.
Save natanlao/fc8923ca5ef326f36cd580d457a2e411 to your computer and use it in GitHub Desktop.
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