问题
I'd like to use fast cpm module installer instead of cpanm in my projects.
Also I install target perl version using perlbrew.
According documentation of cpm -g
option will install modules into current @INC
How to force perlbrew change @INC in Dockerfile ?
Below is part of my 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
When I build Dockerfile output of perl -le 'print for @INC'
is same both times:
/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
But if I do same manually result is ok:
$ 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
回答1:
For starters, "A sub-shell is launched with ..." indicates you have an incorrectly setup perlbrew
. You were instructed to add the following to your shell's startup script:
source "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"/etc/bashrc
Without this, a fallback mechanism is used to try to provide the desired functionality, but it's completely useless outside of interactive shells.
Secondly, this is a rather dubious use of perlbrew. If your docker script worked as intended, it would have far reaching consequences. That's not a good thing. You could use perlbrew use
, but you could instead use the correct perl
build directly using
RUN "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}"/perls/perl-5.31.0/bin/perl -S cpm install -gv CGI
In your case, this should resolve to
RUN /usr/local/perlbrew/perls/perl-5.31.0/bin/perl -S cpm install -gv CGI
for you.
来源:https://stackoverflow.com/questions/56590443/install-modules-with-perlbrew-and-cpm-perlbrew-switch-does-not-change-inc-dur