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?
There are two issues you should fix.
cpanmis not available for installation in the 1st place. Rundocker run -it centos:7.9.2009 /bin/bashand in the container doyum install -y cpanm. I got:When I ran
yum install -y cpanm perl sudo perl-App-cpanminusand thenecho $?the return was0as it did install the other packages. This means that this stage isn't what broke your build. That is because the package you need in order to install packages fromcpanmisperl-App-cpanminus. To fix this, just removecpanmfrom the list of modules to install (since you're already installingperl-App-cpanminus). As this didn't break the build it is not strictly necessary just highly recommended.cpanm install JSONreturned:So as you can see you do not need the word
installthere. Runningecho $?the return code was1, so this is the step that broke your build.Side notes
Dockerfileso I can't tell) the packagesudois redundant.sudoin the command&& sudo cpanm install JSON;is certainly redundant.