In docker container I have a perl script and I need to be able to parse json I tried to have CPAN JSON
installed for perl in my Dockerfile.
So I am doing the following in my Dockerfile
FROM centos:7.9.2009
RUN yum install -y cpanm
perl
perl-App-cpanminus
perl-Config-Tiny
sudo
&& yum clean all
&& sudo cpanm install JSON;
But when I do a docker build
I get:
#0 41.76 Configuring Test-Simple-1.302195 ... OK
#0 41.95 Building and testing Test-Simple-1.302195 ... OK
#0 68.48 Successfully installed Test-Simple-1.302195
#0 68.59 Building and testing JSON-4.10 ... OK
#0 126.9 Successfully installed JSON-4.10
#0 127.0 2 distributions installed
------
ERROR: failed to solve: executor failed running [/bin/sh -c yum install -y cpanm perl perl-App-cpanminus perl-Config-Tiny sudo && yum clean all && sudo cpanm install JSON;]: exit code: 1
What is the problem here?
2
Answers
The problem is that
cpanm
is not available for installation in the 1st place.Run
docker run -it centos:7.9.2009 /bin/bash
and in the container doyum install -y cpanm
.I got:
When I ran
yum install -y cpanm perl sudo perl-App-cpanminus
and thenecho $?
the return was0
as it did install the other packages.I suspect the issue is that the package name is not
capnm
butperl-CPAN
. Notice that the capitalization of the package name matters.After that running the command
cpanm install JSON
returned:This hints that you do not need the word
install
there. Also, if you are running the container without changing your user inside it (we didn’t see theDockerfile
so I can’t tell) the packagesudo
is redundant. As you are still root while installing the packages usingsudo
in the command&& sudo cpanm install JSON;
is certainly redundant.This doesn’t answer your question, but I recently had to debug a cpanm situation by figuring out how to find the cpanm errors (although setting
--verbose
can work too). I wanted to grab the build log.First, find the container ID of whatever the build left behind. This is likely the most recent container, but also the command will have the start of the PERL_CARTON_MIRROR environment variable:
Commit that container to an image by using the container ID (the first column):
Now grab the cpanm build log: