8

I want to update GCC from 4.4.7 to 4.7.2 in a container(CentOS 6.9) following this tutorial How to upgrade GCC on CentOS.

In the end of the tutorial, the author uses scl enable devtoolset-1.1 bash to launch a new shell where all the environments are updated. I write the following Dockerfile:

Run ... \ && yum install devtoolset-1.1 \ && scl enable devtoolset-1.1 bash 

However, when I run the container from the images generated by the Dockerfile, I find that the GCC version is still 4.4.7, which indicates that I enter the old shell.

Though I success in updating GCC in the container by explicitly defining the CC, CPP, CXX variables, I still want to know how to update GCC with "scl" command in a Dockerfile. That's to say, how to enter a new shell in a Dockerfile?

Thank you in advance. ^_^

2 Answers 2

21

To expand on @user2915097's answer here is a working example using devtoolset-7 and rh-python36 instead of 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 
Sign up to request clarification or add additional context in comments.

Comments

10

Among the directives of the Dockerfile, you have SHELL

https://docs.docker.com/engine/reference/builder/#shell

from this doc

The SHELL instruction can also be used on Linux should an alternate shell be required such as zsh, csh, tcsh and others.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.