Perl 映像中缺少 perl 命令

Missing perl command in Perl image

我相信这是一个非常简单的修复。我试图用 Perl(加上一些 Perl)模块构建 Docker 图像。但是,当我转到 运行 时,它说没有 /bin/perl。问题是:

为什么 Perl Docker 图片中没有 Perl?

我的 Docker 文件如下:

FROM perl:5.20

ENV PERL_MM_USE_DEFAULT 1
RUN cpan install Net::SSL inc:latest
RUN mkdir /ssc
COPY /ssc /ssc
RUN mkdir /tmp/ssc-bin-files;cp /ssc/bin/*.sh /tmp/ssc-bin-files;chmod a+rx /tmp/ssc-bin-files/*;cp /tmp/ssc-bin-files/* /ssc/bin
RUN chmod a+rx /ssc/bin/*.sh
ENTRYPOINT ["/ssc/bin/put-and-submit.sh"]

Jenkins 管道片段:

    stage('Build, Tag and Push SSC Dockerfile'){
        tagAsTest = "${IMAGE_NAME}:test"
        REPO = "chq-ic2e-sprint-images-docker-local"
        println "Docker App Build"
        docker.build(tagAsTest,"-f Dockerfile .")
        sh 'docker image ls | grep rules-client'
    }
              
    stage('Set image tag to :approved'){
        hasReachedDockerComposeUp=false;
        REPO = "chq-ic2e-sprint-images-docker-local"
        sh "docker tag ${IMAGE_NAME}:test ${IMAGE_NAME}:approved"
        buildInfo = rtDocker.push("${IMAGE_NAME}:approved", REPO , buildInfo)
        server.publishBuildInfo buildInfo
    }

Jenkins 日志如下:

[Pipeline] sh
+ docker build -t chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:test -f Dockerfile .
Sending build context to Docker daemon  39.42kB

Step 1/8 : FROM perl:5.20
 ---> bbe5a82c1dbe
Step 2/8 : ENV PERL_MM_USE_DEFAULT 1
 ---> Using cache
 ---> ca2769a89ab8
Step 3/8 : RUN cpan install Net::SSL inc:latest
 ---> Using cache
 ---> 1e53f0573131
Step 4/8 : RUN mkdir /ssc
 ---> Using cache
 ---> a324effec8ce
Step 5/8 : COPY /ssc /ssc
 ---> d40bf34f8565
Step 6/8 : RUN mkdir /tmp/ssc-bin-files;cp /ssc/bin/*.sh /tmp/ssc-bin-files;chmod a+rx /tmp/ssc-bin-files/*;cp /tmp/ssc-bin-files/* /ssc/bin
 ---> Running in 02386f41174f
Removing intermediate container 02386f41174f
 ---> 4767a8e6f23a
Step 7/8 : RUN chmod a+rx /ssc/bin/*.sh
 ---> Running in 07646aa96048
Removing intermediate container 07646aa96048
 ---> f070fcd8a9e9
Step 8/8 : ENTRYPOINT ["/ssc/bin/put-and-submit.sh"]
 ---> Running in e6bab12f8f40
Removing intermediate container e6bab12f8f40
 ---> 1422df9d957b
Successfully built 1422df9d957b
Successfully tagged chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:test
[Pipeline] sh
+ docker image ls
+ grep rules-client
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/rules-client                   approved            da334d1d8fae        2 days ago          22.5MB
chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/rules-client                   test                da334d1d8fae        2 days ago          22.5MB

脚本正在通过管道 运行 像这样:

    stage('Run image'){
      sh '''
      docker run -i -v \
      --mount type=bind,source="$(pwd)/host-dirs,target=/host-dirs" \
      chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:approved
      sh
      '''
    }

或从这样的终端:

#!/bin/bash
docker run -it \
 --mount type=bind,source="$(pwd)/host-dirs,target=/host-dirs" \
 chq-ic2e-sprint-images-docker-local.artifactory.swg-devops.com/ssc-cost-file-processor:approved sh

perl 二进制文件可能在 /usr/local/bin/perl 中。您可以在 运行 容器中的 shell 中检查。

host> docker exec -it your_container bash
container> which perl
/usr/local/bin/perl
container> exit

里面确实有perl version 5.20。我只是对您 docker 文件中的入口点脚本感到好奇。当容器启动时,您默认 运行ning 一个 shell 脚本。什么脚本开始或 运行s?如果你想 运行 perl 而不进入容器,使用 --entrypoint=perl 和你的 docker 运行 命令。

docker run --rm --name perl perl:5.20 perl --version
### Output
This is perl 5, version 20, subversion 3 (v5.20.3) built for x86_64-linux
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2015, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
###