我想在docker构建阶段进行研究。我已经成功安装了一个perl,但是无法perlbrew switch
安装它,因此cpanm
将模块安装到错误的位置。
Dockerfile如下。
FROM centos:centos7
SHELL ["/bin/bash", "-c"]
RUN yum -y update
RUN yum -y groupinstall "Development Tools"
RUN yum -y install iproute cpan gcc perl-ExtUtils-Manifest
RUN curl -L https://install.perlbrew.pl | SHELL=/bin/bash bash
RUN echo "source /root/perl5/perlbrew/etc/bashrc" >> /root/.bashrc
RUN \source ~/perl5/perlbrew/etc/bashrc
RUN /root/perl5/perlbrew/bin/perlbrew install --notest --noman perl-5.30.0
RUN /root/perl5/perlbrew/bin/perlbrew install-cpanm
RUN /root/perl5/perlbrew/bin/perlbrew switch perl-5.30.0
RUN /root/perl5/perlbrew/bin/cpanm File::Find::Rule
CMD /sbin/init
它在perlbrew switch
上失败,并显示错误。
Step 6/13 : RUN curl -L https://install.perlbrew.pl | SHELL=/bin/bash bash
---> Running in 2d003bbacf0e
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 170 100 170 0 0 189 0 --:--:-- --:--:-- --:--:-- 189
100 1548 100 1548 0 0 1261 0 0:00:01 0:00:01 --:--:-- 0
## Download the latest perlbrew
## Installing perlbrew
Using Perl </usr/bin/perl>
perlbrew is installed: ~/perl5/perlbrew/bin/perlbrew
perlbrew root (~/perl5/perlbrew) is initialized.
Append the following piece of code to the end of your ~/.bash_profile and start a
new shell, perlbrew should be up and fully functional from there:
source ~/perl5/perlbrew/etc/bashrc
Simply run `perlbrew` for usage details.
Happy brewing!
## Installing patchperl
## Done.
Removing intermediate container 2d003bbacf0e
---> cf3fe0430858
Step 7/13 : RUN echo "source /root/perl5/perlbrew/etc/bashrc" >> /root/.bashrc
---> Running in 835a04a14f9f
Removing intermediate container 835a04a14f9f
---> d06c29928706
Step 8/13 : RUN \source ~/perl5/perlbrew/etc/bashrc
---> Running in e655fe87bc0c
Removing intermediate container e655fe87bc0c
---> fbc2aa1dcbb7
Step 9/13 : RUN /root/perl5/perlbrew/bin/perlbrew install --notest --noman perl-5.30.0
---> Running in 1bb4851a6e5d
Fetching perl 5.30.0 as /root/perl5/perlbrew/dists/perl-5.30.0.tar.gz
Download http://www.cpan.org/src/5.0/perl-5.30.0.tar.gz to /root/perl5/perlbrew/dists/perl-5.30.0.tar.gz
Installing /root/perl5/perlbrew/build/perl-5.30.0/perl-5.30.0 into ~/perl5/perlbrew/perls/perl-5.30.0
This could take a while. You can run the following command on another shell to track the status:
tail -f ~/perl5/perlbrew/build.perl-5.30.0.log
perl-5.30.0 is successfully installed.
Removing intermediate container 1bb4851a6e5d
---> 5c2f139f28c4
Step 10/13 : RUN /root/perl5/perlbrew/bin/perlbrew install-cpanm
---> Running in c8650ea79674
cpanm is installed to
/root/perl5/perlbrew/bin/cpanm
Removing intermediate container c8650ea79674
---> c3e92218cf8f
Step 11/13 : RUN /root/perl5/perlbrew/bin/perlbrew switch perl-5.30.0
---> Running in 551369fc6a61
Use of uninitialized value $shell in pattern match (m//) at /root/perl5/perlbrew/bin/perlbrew line 2445.
Use of uninitialized value $shell in concatenation (.) or string at /root/perl5/perlbrew/bin/perlbrew line 2485.
A sub-shell is launched with perl-5.30.0 as the activated perl. Run 'exit' to finish it.
HOSTNAME=551369fc6a61
SHELL=
PATH=/root/perl5/perlbrew/bin:/root/perl5/perlbrew/perls/perl-5.30.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/env
PWD=/
HOME=/root
SHLVL=2
PERLBREW_PERL=perl-5.30.0
PERLBREW_VERSION=0.86
MANPATH=/root/perl5/perlbrew/perls/perl-5.30.0/man:
PERL_LOCAL_LIB_ROOT=
PERL5LIB=
PERLBREW_MANPATH=/root/perl5/perlbrew/perls/perl-5.30.0/man
PERLBREW_LIB=
PERLBREW_SKIP_INIT=1
PERLBREW_PATH=/root/perl5/perlbrew/bin:/root/perl5/perlbrew/perls/perl-5.30.0/bin
PERLBREW_ROOT=/root/perl5/perlbrew
Removing intermediate container 551369fc6a61
---> b76db56bd82f
Step 12/13 : RUN /root/perl5/perlbrew/bin/cpanm File::Find::Rule
---> Running in 5574895c6069
--> Working on File::Find::Rule
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/File-Find-Rule-0.34.tar.gz ... OK
Configuring File-Find-Rule-0.34 ... OK
==> Found dependencies: Test::More, Text::Glob, Number::Compare
--> Working on Test::More
Fetching http://www.cpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302167.tar.gz ... OK
Configuring Test-Simple-1.302167 ... OK
Building and testing Test-Simple-1.302167 ... OK
Successfully installed Test-Simple-1.302167
--> Working on Text::Glob
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/Text-Glob-0.11.tar.gz ... OK
Configuring Text-Glob-0.11 ... OK
Building and testing Text-Glob-0.11 ... OK
Successfully installed Text-Glob-0.11
--> Working on Number::Compare
Fetching http://www.cpan.org/authors/id/R/RC/RCLAMP/Number-Compare-0.03.tar.gz ... OK
Configuring Number-Compare-0.03 ... OK
Building and testing Number-Compare-0.03 ... OK
Successfully installed Number-Compare-0.03
Building and testing File-Find-Rule-0.34 ... OK
Successfully installed File-Find-Rule-0.34
4 distributions installed
Removing intermediate container 5574895c6069
---> b7cbd8213dcc
Step 13/13 : CMD /sbin/init
---> Running in 3180df4e4deb
Removing intermediate container 3180df4e4deb
---> b6ebc0ca82a5
Successfully built b6ebc0ca82a5
我还尝试在centos7 / ubuntu上切换/使用perl-5.28.2,结果相同。
它仅在构建阶段失败,并且在构建之后可以通过附加到容器来成功perlbrew switch
。
造成这种情况的直接原因似乎是在使用perlbrew swich / use分叉的子外壳中缺少shell
环境变量。
Use of uninitialized value $shell in pattern match (m//) at /root/perl5/perlbrew/bin/perlbrew line 2445.
我该如何解决问题?
我的环境是
App::Perlbrew 0.86
Docker version 19.03.1, build 74b1e89