Build a docker image which includes the plenv + cpanm + carton Perl toolchain.
- plenv - Perl installation manager
- cpanm - CPAN installer
- carton - Module dependency manager (like Bundler in Ruby)
Choose your Perl version by changing PLENV_VERSION
in Dockerfile
or overwrite PLENV_VERSION
with the -e
option
cd docker-perl-toolchain
docker build -t [repositoryname] .
The docker image itself is available on Docker Hub: docker-perl-toolchain image.
Suppose you wish to run a script (corecheck.pl
) which prints the CPU information of the host. Then you would have these three files:
cpanfile
:
requires "Sys::Info", "0.78";
corecheck.pl
:
use Sys::Info;
use Sys::Info::Constants qw( :device_cpu );
my $info = Sys::Info->new;
my $cpu = $info->device( CPU => %options );
printf "CPU: %s\n", scalar($cpu->identify) || 'N/A';
printf "CPU speed is %s MHz\n", $cpu->speed || 'N/A';
printf "There are %d CPUs\n" , $cpu->count || 1;
printf "CPU load: %s\n" , $cpu->load || 0;
Dockerfile
:
FROM bogaotory/perl-toolchain
ADD cpanfile /build/cpanfile
ADD corecheck.pl /build/corecheck.pl
WORKDIR build
RUN . /etc/profile \
&& carton install # This happens in the WORKDIR, modules are installed in /build/local directory
ENTRYPOINT . /etc/profile \
&& carton exec perl corecheck.pl
Here is a list of articles/posts/repos I read in order to make this Dockerfile:
- Dockerising a Perl application
- Modern Perl toolchain for Git managed web apps
- https://github.com/miyagawa/docker-plenv-vanilla
- https://github.com/moltar/docker.plenv
- Understanding a little more about /etc/profile and /etc/bashrc
- Best practices for writing Dockerfiles
- Which cpan installer is the right one? (CPAN.pm/CPANPLUS/cpanminus)
- Number of CPU/Cores in Perl