gpt4 book ai didi

docker - 默认启用 scl 工具集

转载 作者:行者123 更新时间:2023-12-04 19:39:56 25 4
gpt4 key购买 nike

我正在尝试创建一个 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 的东西进入交互式外壳。
不幸的是,上面默认会启动 non-login shell , .bash_profile只有在 login shell 中时才被调用, 使其作为 login shell ,需要使用next进入容器:

docker run -it imagename bash -l

-l Make bash act as if it had been invoked as a login 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 查看使其成为登录外壳, .bash_profile被执行。

关于docker - 默认启用 scl 工具集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68203238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com