Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start another bash in Dockerfile

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. ^_^

like image 831
pikatao Avatar asked Apr 27 '17 07:04

pikatao


People also ask

Can Dockerfile run 2 commands?

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. If CMD is used to provide default arguments for the ENTRYPOINT instruction, both the CMD and ENTRYPOINT instructions should be specified with the JSON array format.

How do I run a docker shell?

Using the Docker run command to run a container and access its shell. Using the Docker exec command to run commands in an active container. Using the Docker start command and attach a shell to a stopped container.

What is docker exec bash?

The Docker exec command is a very useful command for interacting with your running docker containers. When working with Docker you will likely have the need to access the shell or CLI of the docker containers you have deployed, which you can do using docker exec .


1 Answers

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
like image 108
inetknght Avatar answered Oct 23 '22 08:10

inetknght