Search code examples
dockerperldockerfile

Why PERL5LIB env variable is disappeared after `source $PERLBREW_ROOT/etc/bashrc`?


In my Dockerfile I have next command:

FROM perl:5.30.3-buster
...
RUN  env && source $PERLBREW_ROOT/etc/bashrc &&  env  &&  carton install

when source $PERLBREW_ROOT/etc/bashrc was executed the PERL5LIB is disappeared and carton can not find libraries indicated by PERL5LIB path

Output from command:

Step 18/22 : RUN  env && source $PERLBREW_ROOT/etc/bashrc &&  env  &&  carton install
 ---> Running in 358cb3aa042e
HOSTNAME=358cb3aa042e
PERL_VERSION=5.34.1
PERLBREW_HOME=/opt/perlbrew/home
PWD=/
HOME=/root
PERL5LIB=/opt/proj/lib:/opt/proj/local/lib/perl5:
SHLVL=1
PATH=/opt/perlbrew/bin:/opt/proj/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PERLBREW_ROOT=/opt/perlbrew
_=/usr/bin/env

HOSTNAME=358cb3aa042e
PERL_VERSION=5.34.1
PERLBREW_PATH=/opt/perlbrew/bin:/opt/perlbrew/perls/perl-5.34.1/bin
PERLBREW_HOME=/opt/perlbrew/home
PERLBREW_SHELLRC_VERSION=0.94
PWD=/
MANPATH=/opt/perlbrew/perls/perl-5.34.1/man:
PERLBREW_PERL=perl-5.34.1
HOME=/root
PERLBREW_VERSION=0.94
SHLVL=1
PATH=/opt/perlbrew/bin:/opt/perlbrew/perls/perl-5.34.1/bin:/opt/proj/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PERLBREW_ROOT=/opt/perlbrew
PERLBREW_MANPATH=/opt/perlbrew/perls/perl-5.34.1/man
_=/usr/bin/env

But running same command on host system does not wipe PERL5LIB:

(env | grep PERL) && source ~/perl5/perlbrew/etc/bashrc && (env | grep PERL)
PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.30.3/bin
PERLBREW_HOME=/home/kes/.perlbrew
PERLBREW_SHELLRC_VERSION=0.89
PERLBREW_PERL=perl-5.30.3
PERLBREW=command perlbrew
PERLBREW_VERSION=0.89
PERL5LIB=xxx
PERLBREW_ROOT=/home/kes/perl5/perlbrew
PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.30.3/man
PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.30.3/bin
PERLBREW_HOME=/home/kes/.perlbrew
PERLBREW_SHELLRC_VERSION=0.89
PERLBREW_PERL=perl-5.30.3
PERLBREW=command perlbrew
PERLBREW_VERSION=0.89
PERL5LIB=xxx
PERLBREW_ROOT=/home/kes/perl5/perlbrew
PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.30.3/man

Tell me please, what is the problem when running that command from Docker file while building container?


Solution

  • Thank you @ikegami

    It was unset by ${PERLBREW_HOME:-}/init. This unset required when you switch between perls and do not want theirs libraries mixed with each other.

    For example you are on perl-5.24 and have installed libraries into its PERL5LIB, then you switched to perl-5.28 but PERL5LIB still points to modules installed by different version of perl. This may cause coredumps.