我想按照本教程How to upgrade GCC on CentOS在容器(CentOS 6.9)中将GCC从4.4.7更新到4.7.2。
在本教程结束时,作者使用scl enable devtoolset-1.1 bash
启动了一个更新所有环境的新shell。我写了以下Dockerfile:
Run ... \
&& yum install devtoolset-1.1 \
&& scl enable devtoolset-1.1 bash
但是,当我从Dockerfile生成的图像中运行容器时,我发现GCC版本仍然是4.4.7,这表明我进入旧shell。
虽然我通过明确定义CC,CPP,CXX变量成功更新容器中的GCC,但我仍然想知道如何在Dockerfile中使用“scl”命令更新GCC。 那就是说,如何在Dockerfile中输入新shell?
提前谢谢你。 ^ _ ^
答案 0 :(得分:6)
在Dockerfile的指令中,你有SHELL
https://docs.docker.com/engine/reference/builder/#shell
来自此文档
The SHELL instruction can also be used on Linux should an alternate shell be required such as zsh, csh, tcsh and others.
答案 1 :(得分:5)
要扩展@ user2915097的答案,这里是一个使用devtoolset-7
和rh-python36
而不是devtoolset-1.1
的有效示例
FROM centos:7
# Default version of GCC and Python
RUN gcc --version && python --version
# Install some developer style software collections with intent to
# use newer version of GCC and Python than the OS provided
RUN yum install -y centos-release-scl && yum install -y devtoolset-7 rh-python36
# Yum installed packages but the default OS-provided version is still used.
RUN gcc --version && python --version
# Okay, change our shell to specifically use our software collections.
# (default was SHELL [ "/bin/sh", "-c" ])
# https://docs.docker.com/engine/reference/builder/#shell
#
# See also `scl` man page for enabling multiple packages if desired:
# https://linux.die.net/man/1/scl
SHELL [ "/usr/bin/scl", "enable", "devtoolset-7", "rh-python36" ]
# Switching to a different shell has brought the new versions into scope.
RUN gcc --version && python --version