skip to Main Content

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


  1. 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 do yum install -y cpanm.
    I got:

    No package cpanm available.
    Error: Nothing to do

    When I ran yum install -y cpanm perl sudo perl-App-cpanminus and then echo $? the return was 0 as it did install the other packages.

    I suspect the issue is that the package name is not capnm but perl-CPAN. Notice that the capitalization of the package name matters.
    After that running the command cpanm install JSON returned:

    [root@aabe6178c007 /]# cpanm install JSON
    --> Working on install
    Fetching http://www.cpan.org/authors/id/D/DA/DAGOLDEN/install-0.01.tar.gz ... OK
    Configuring install-0.01 ... OK
    Building and testing install-0.01 ... FAIL
    ! Installing install failed. See /root/.cpanm/work/1692109504.103/build.log for details. Retry with --force to force install it.
    --> Working on JSON
    Fetching http://www.cpan.org/authors/id/I/IS/ISHIGAKI/JSON-4.10.tar.gz ... OK
    Configuring JSON-4.10 ... OK
    ==> Found dependencies: Test::More
    --> Working on Test::More
    Fetching http://www.cpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302195.tar.gz ... OK
    Configuring Test-Simple-1.302195 ... OK
    Building and testing Test-Simple-1.302195 ... OK
    Successfully installed Test-Simple-1.302195
    Building and testing JSON-4.10 ... OK
    Successfully installed JSON-4.10
    2 distributions installed
    [root@aabe6178c007 /]#
    

    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 the Dockerfile so I can’t tell) the package sudo is redundant. As you are still root while installing the packages using sudo in the command && sudo cpanm install JSON; is certainly redundant.

    Login or Signup to reply.
  2. 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:

    $ docker ps -a
    CONTAINER ID   IMAGE                    COMMAND     ...
    2eae7f9e757a   9e2398121731             "cpanm …"   ...
    

    Commit that container to an image by using the container ID (the first column):

    $ docker commit 2eae7f9e757a
    sha256:6887b59a7ed957c3ff38d0652929847a1ef200461e8f117c6a2746f066206b3f
    

    Now grab the cpanm build log:

    $ docker cp -L 6887b59a7ed9:/root/.cpanm/build.log build.log
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search