【发布时间】:2019-06-14 01:48:11
【问题描述】:
我想在我的项目中使用快速的cpm 模块安装程序而不是 cpanm。
我还使用 perlbrew 安装目标 perl 版本。
根据 cpm -g 选项的documentation 将模块安装到当前@INC 中
如何在 Dockerfile 中强制 perlbrew 更改 @INC ?
以下是我的 Dockerfile 的一部分
RUN perl -le 'print for @INC' && \
perlbrew switch perl-5.31.0 && \
perl -le 'print for @INC' && \
cpm install -gv CGI && \
perlbrew list-modules
当我构建 Dockerfile 时,perl -le 'print for @INC' 的输出两次都相同:
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base
但如果我手动执行相同的操作,结果是可以的:
$ docker run -it pavelsr/xxxhub
root@1a34ea34a3fb:/# perl -le 'print for @INC'
/etc/perl
/usr/local/lib/x86_64-linux-gnu/perl/5.22.1
/usr/local/share/perl/5.22.1
/usr/lib/x86_64-linux-gnu/perl5/5.22
/usr/share/perl5
/usr/lib/x86_64-linux-gnu/perl/5.22
/usr/share/perl/5.22
/usr/local/lib/site_perl
/usr/lib/x86_64-linux-gnu/perl-base
.
root@1a34ea34a3fb:/# perlbrew switch perl-5.31.0
A sub-shell is launched with perl-5.31.0 as the activated perl. Run 'exit' to finish it.
root@1a34ea34a3fb:/# perl -le 'print for @INC'
/usr/local/perlbrew/perls/perl-5.31.0/lib/site_perl/5.31.0/x86_64-linux
/usr/local/perlbrew/perls/perl-5.31.0/lib/site_perl/5.31.0
/usr/local/perlbrew/perls/perl-5.31.0/lib/5.31.0/x86_64-linux
/usr/local/perlbrew/perls/perl-5.31.0/lib/5.31.0
root@1a34ea34a3fb:/# cpm install -g CGI
DONE install HTML-Tagset-3.20
DONE install HTML-Parser-3.72
DONE install CGI-4.44
3 distributions installed.
root@1a34ea34a3fb:/# perlbrew list-modules
CGI
HTML::Parser
HTML::Tagset
Perl
【问题讨论】:
-
Re "A sub-shell is launch with",好吧,首先,您没有按照说明将
source "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"/etc/bashrc添加到.bashrc。perlbrew use和perlbrew switch只需操作PATH。为了能够做到这一点,源脚本在 shell 中创建了一个名为perlbrew的函数。作为缺少这些功能时的后备方案,还有一个名为perlbrew的脚本。该脚本显然无法更改调用它的 shell 的PATH,因此它会启动一个子 shell,而改用已修复的PATH。 -
因此,如果没有这些功能,您的管道不可能受到
perlbrew switch的影响。首先解决这个问题。 -
Re "如何在 Dockerfile 中强制 perlbrew 更改 @INC ?",尽管重复声明声称您想要更改
@INC,但这不是您想要做的。您实际上想更改正在使用的perl的安装。 -
@ikegami 非常感谢您的详细解释。但我不知道 perlbrew 如何以及何时修复
$PATH。我尝试在RUN echo 'source "${PERLBREW_ROOT}"/etc/bashrc' >> .bashrc之前和之后打印$PATH,步骤,它没有改变,在这两种情况下都是/usr/local/perlbrew/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin。 -
目前我只是直接在
Dockerfile中设置PATH:ENV PATH ${PERLBREW_ROOT}/perls/perl-$PERL_VERSION/bin:$PATH
标签: perl docker perlbrew cpanm