默认情况下启用scl工具集



我正在尝试创建一个docker映像,其中llvm-toolset-7在映像运行时自动启用。

上下文是这个映像,因为它是从rustembedded/cross:x86_64-unknown-linux-gnu扩展而来的,所以要交叉编译到linux。由于出于我的目的,我需要最新版本的llvm,我需要在启动机器时默认启用工具集,因为交叉编译命令是由交叉cli运行的,而不是由我手动运行的。

我在Dockerfile的尝试是:

FROM rustembedded/cross:x86_64-unknown-linux-gnu
RUN yum update -y && 
yum install centos-release-scl -y && 
yum install llvm-toolset-7 -y && 
yum install scl-utils -y && 
echo "source scl_source enable llvm-toolset-7" >> ~/.bash_profile

然而,当我在docker桌面中打开交互式shell时,它并没有默认为启用了工具集的bash shell。

我是一个非常频繁的Ubuntu用户,但这张图片是基于CentOS的,我很难理解工具集。

我猜您使用类似docker run -it imagename bash的东西来进入交互式shell。

不幸的是,上面默认情况下会启动一个non-login shell.bash_profile只有在login shell中时才会被调用,为了使其像login shell一样工作,您需要使用next来进入容器:

docker run -it imagename bash -l

-l让bash像被调用为登录shell 一样

最小示例

Dockerfile:

FROM rustembedded/cross:x86_64-unknown-linux-gnu
RUN echo "export ABC=1" >> ~/.bash_profile

执行:

$ docker build -t abc:1 .
$ docker run --rm -it abc:1 bash
[root@669149c2bc8b /]# env | grep ABC
[root@669149c2bc8b /]#
[root@669149c2bc8b /]# exit
$ docker run --rm -it abc:1 bash -l
[root@7be9b9b8e906 /]# env | grep ABC
ABC=1

您可以看到,使用-l将其作为登录shell,.bash_profile将被执行。

最新更新