centos - How to make devtoolset g++ available for Makefile in docker's centos7? - Unix & Linux Stack Exchange
how to install devtoolset-8 / GCC 8 on Amazon Linux 2 - Stack Overflow
rhel8 - How to Install devtoolset 8 in RHEL 8 image - Stack Overflow
docker - How to start another bash in Dockerfile - Stack Overflow
According to the comments and my own experience with Docker, each RUN line is run in a separate shell environment, so when you source an environment in one RUN line, that environment is not available to other RUN commands.
Using the line RUN source scl_source enable devtoolset-7 && cd /home/admin/${APP_NAME}/nginx-base/cplusplus && make version && make instead of your previous RUN command makes sure the current environment is setup for the make command.
As a workaround:
SHELL ["sh", "-c", "source scl_source enable $(scl -l) && sh -c \"$0\" \"$@\""]
it replaces the shell for all following RUN.
devtoolset is called gcc-toolset in RHEL8.
The following commands worked for me:
microdnf install -y gcc-toolset-12
scl enable gcc-toolset-12 bash
gcc --version
# gcc (GCC) 12.1.1 20220628 (Red Hat 12.1.1-3)
According to that article, you can check if you have access to Red Hat Software Collections (RHSCL) by running the following command by the root user:
$ su -
# subscription-manager repos --list | egrep rhscl
If you have, enable necessary software repo and then install devtoolset:
# subscription-manager repos --enable rhel-7-server-optional-rpms
# yum install devtoolset-8
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
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.
FROM centos:centos7
RUN yum update -y
RUN yum groupinstall "Development Tools" -y
RUN yum install wget -y
RUN curl -O https://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.gz
RUN tar xzf gcc-7.3.0.tar.gz
RUN cd gcc-7.3.0
RUN ./contrib/download_prerequisites
RUN cd ..
RUN mkdir gcc-build
RUN cd gcc-build
RUN ../gcc-7.3.0/configure \
--enable-shared \
--enable-threads=posix \
--enable-__cxa_atexit \
--enable-clocale=gnu \
--disable-multilib \
--enable-languages=all
RUN make
# (Go make a cup of ice tea :)
RUN make install
To save the build time you can create a new docker from the running docker using "docker commit" or save /usr/local to a tar file and open it on any other fresh centos7 docker.
Following commands in Dockerfile worked for me:
RUN yum install -y centos-release-scl
RUN yum install -y devtoolset-7-gcc-*
RUN echo "source scl_source enable devtoolset-7" >> /etc/bashrc
RUN source /etc/bashrc