diff --git a/perl/content.md b/perl/content.md index 2d6f6a3a9..0629f2b8e 100644 --- a/perl/content.md +++ b/perl/content.md @@ -31,3 +31,23 @@ For many simple, single file projects, you may find it inconvenient to write a c ```console $ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp perl:5.20 perl your-daemon-or-script.pl ``` + +## Creating a reusable `perl:onbuild` image for Perl projects + +Suppose you have a project that uses [Carton](https://metacpan.org/pod/Carton) to manage Perl dependencies. You can write a `Dockerfile` that makes use of the [ONBUILD](https://docs.docker.com/engine/reference/builder/#onbuild) instruction like this: + +```dockerfile +FROM perl:5.26 + +RUN cpanm Carton \ + && mkdir -p /usr/src/app +WORKDIR /usr/src/app + +ONBUILD COPY cpanfile* /usr/src/myapp +ONBUILD RUN carton install + +ONBUILD COPY . /usr/src/app +``` + +Building this as a `perl:onbuild` image can let you reduce your project's `Dockerfile` into a single line of `FROM perl:onbuild`, which may be enough to build a stand-alone image for your project. +