1.8. Using Red Hat Developer Toolset Container Images

Docker-formatted container images can be used to run Red Hat Developer Toolset components inside virtual software containers, thus isolating them from the host system and allowing for their rapid deployment. This section describes how to install and use pre-built container images with Red Hat Developer Toolset components, as well as how to obtain Red Hat Developer Toolset Dockerfiles for building custom container images and how to use the resulting images.

Note

The docker package, which contains the Docker daemon, command line tool, and other necessary components for building and using docker-formatted container images, is currently only available for the Server variant of the Red Hat Enterprise Linux 7 product. Docker-formatted container images cannot be run on Red Hat Enterprise Linux 6, and Red Hat Developer Toolset Dockerfiles are not distributed for Red Hat Enterprise Linux 6.
Follow the instructions outlined at Getting Docker in RHEL 7 to set up an environment for building and using docker-formatted container images.

1.8.1. Using Pre-Built Container Images

Pre-built docker-formatted container images are available that contain selected toolchain and perftools components of Red Hat Developer Toolset. This section describes how to obtain the pre-built Red Hat Developer Toolset docker-formatted container images and how to run Red Hat Developer Toolset components using these images.
The following images are available from the Red Hat Container Registry at registry.access.redhat.com:
  • rhscl/devtoolset-4-toolchain-rhel7
    The image contains the following Red Hat Developer Toolset components:
    • devtoolset-4-gcc
    • devtoolset-4-gcc-c++
    • devtoolset-4-gcc-fortran
    • devtoolset-4-gdb
  • rhscl/devtoolset-4-perftools-rhel7
    The image contains all Red Hat Developer Toolset components included in the devtoolset-4-perftools metapackage:
    • devtoolset-4-oprofile
    • devtoolset-4-systemtap
    • devtoolset-4-valgrind
    • devtoolset-4-dyninst

1.8.1.1. Pulling Pre-Built Container Images from the Registry

To pull a pre-built Red Hat Developer Toolset docker-formatted container image from the registry to your local machine, run the following command as root:
docker pull image_name
Substitute the image_name parameter with the name of the container image. For example, to pull the image containing selected Red Hat Developer Toolset toolchain components (rhscl/devtoolset-4-toolchain-rhel7), run the following command as root:
~]# docker pull rhscl/devtoolset-4-toolchain-rhel7

1.8.1.2. Running Red Hat Developer Toolset Tools from Pre-Built Container Images

To display general usage information for pre-built Red Hat Developer Toolset docker-formatted container images that you have already pulled to your local machine (see Section 1.8.1.1, “Pulling Pre-Built Container Images from the Registry”), run the following command as root:
docker run image_name usage
To launch an interactive shell within a pre-built docker-formatted container image, run the following command as root:
docker run -ti image_name /bin/bash -l
In both of the above commands, substitute the image_name parameter with the name of the container image you pulled to your local system and now want to use.
For example, to launch an interactive shell within the container image with selected toolchain components, run the following command as root:
~]# docker run -ti rhscl/devtoolset-4-toolchain-rhel7 /bin/bash -l

Example 1.1. Using GCC in the Pre-Built Red Hat Developer Toolset Toolchain Image

This example illustrates how to obtain and launch the pre-built docker-formatted container image with selected toolchain components of the Red Hat Developer Toolset and how to run the gcc compiler within that image.
  1. Make sure you have a Docker environment set up properly on your system by following instructions at Getting Docker in RHEL 7.
  2. Pull the pre-built toolchain Red Hat Developer Toolset container image from the official Red Hat Container Registry:
    ~]# docker pull rhscl/devtoolset-4-toolchain-rhel7
  3. To launch the container image with an interactive shell, issue the following command:
    ~]# docker run -ti rhscl/devtoolset-4-toolchain-rhel7 /bin/bash -l
  4. To launch the container as a regular (non-root) user, use the sudo command. To map a directory from the host system to the container file system, include the -v (or --volume) option in the docker command:
    ~]$ sudo docker run -v ~/Source:/src -ti rhscl/devtoolset-4-toolchain-rhel7 /bin/bash -l
    In the above command, the host's ~/Source/ directory is mounted as the /src/ directory within the container.
  5. Once you are in the container's interactive shell, you can run Red Hat Developer Toolset tools as expected. For example, to verify the version of the gcc compiler, run:
    bash-4.2$ gcc -v
    [...]
    gcc version 5.2.1 20150716 (Red Hat 5.2.1-1) (GCC)

1.8.2. Using Container Images Built from Dockerfiles

Dockerfiles are available for selected Red Hat Developer Toolset components. Dockerfiles are text files that contain instructions for automated building of docker-formatted container images. This section describes how to obtain Red Hat Developer Toolset Dockerfiles, how to use them to build docker-formatted container images, and how to run Red Hat Developer Toolset components using the resulting container images.
Red Hat Developer Toolset 4.1 for Red Hat Enterprise Linux 7 is shipped with the following Dockerfiles:
  • devtoolset-4-dyninst
  • devtoolset-4-elfutils
  • devtoolset-4-oprofile
  • devtoolset-4-systemtap
  • devtoolset-4-toolchain
  • devtoolset-4-valgrind
  • devtoolset-4

1.8.2.1. Obtaining Dockerfiles

The Red Hat Developer Toolset Dockerfiles are provided by the devtoolset-4-dockerfiles package. The package contains individual Dockerfiles for building docker-formatted container images with individual components and a meta-Dockerfile for building a docker-formatted container image with all the components offered. To be able to use the Dockerfiles, install this package by executing:
~]# yum install devtoolset-4-dockerfiles

1.8.2.2. Building Container Images

Change to the directory where the Dockerfile is installed and run the following command as root:
docker build -t image_name
Replace image_name with the desired name for the new image.

Example 1.2. Building a Container Image with a Red Hat Developer Toolset Component

To build a docker-formatted container image for deploying the elfutils tools in a container, follow the instructions below:
  1. Make sure you have a Docker environment set up properly on your system by following instructions at Getting Docker in RHEL 7.
  2. Install the package containing the Red Hat Developer Toolset Dockerfiles:
    ~]# yum install devtoolset-4-dockerfiles
  3. Determine where the Dockerfile for the required component is located:
    ~]# rpm -ql devtoolset-4-dockerfiles | grep "elfutils/Dockerfile"
    /opt/rh/devtoolset-4/root/usr/share/devtoolset-4-dockerfiles/rhel7/devtoolset-4-elfutils/Dockerfile
  4. Change to the directory where the required Dockerfile is installed:
    ~]# cd /opt/rh/devtoolset-4/root/usr/share/devtoolset-4-dockerfiles/rhel7/devtoolset-4-elfutils/
  5. Build the container image:
    ~]# docker build -t devtoolset-4-elfutils-7 .
    Replace devtoolset-4-elfutils-7 with the name you wish to assign to your resulting container image.

1.8.2.3. Running Red Hat Developer Toolset Tools from Custom-Built Container Images

To display general usage information for images built from Red Hat Developer Toolset Dockerfiles (see Section 1.8.2.2, “Building Container Images”), run the following command as root:
docker run image_name container-usage
To launch an interactive shell within a docker-formatted container image you built, run the following command as root:
docker run -ti image_name /bin/bash -l
In both of the above commands, substitute the image_name parameter with the name of the container image you chose when building it.

Example 1.3. Using elfutils in a Custom-Built Red Hat Developer Toolset Image

This example illustrates how to launch a custom-built docker-formatted container image (built in Example 1.2, “Building a Container Image with a Red Hat Developer Toolset Component”) with the elfutils component and how to run the eu-size tool within that image.
  1. To launch the container image with an interactive shell, issue the following command:
    ~]# docker run -ti devtoolset-4-elfutils-7 /bin/bash -l
  2. To launch the container as a regular (non-root) user, use the sudo command. To map a directory from the host system to the container file system, include the -v (or --volume) option in the docker command:
    ~]$ sudo docker run -v ~/Source:/src -ti devtoolset-4-elfutils-7 /bin/bash -l
    In the above command, the host's ~/Source/ directory is mounted as the /src/ directory within the container.
  3. Once you are in the container's interactive shell, you can run Red Hat Developer Toolset tools as expected. For example, to verify the version of the eu-size tool, run:
    bash-4.2$ eu-size -V
    size (elfutils) 0.163
    [...]
Using the SystemTap Tool from Container Images
When using the SystemTap tool from a container image (built using the Dockerfile supplied by the devtoolset-4-dockerfiles package or from the pre-built perftools image), additional configuration is required, and the container needs to be run with special command-line options.
The following three conditions need to be met:
  1. The image needs to be run with super-user privileges. To do this, run the image using the following command:
    ~]$ docker run --ti --privileged --ipc=host --net=host --pid=host devtoolset-4-systemtap /bin/bash -l
    The above command assumes that you named the image devtoolset-4-systemtap when you built it from the Dockerfile (/opt/rh/devtoolset-4/root/usr/share/devtoolset-4-dockerfiles/rhel7/devtoolset-4-systemtap/Dockerfile).
    To use the perftools image, substitute the image name for devtoolset-4-perftools-rhel7 in the above command.
  2. The following kernel packages need to be installed in the container:
    kernel
    kernel-devel
    kernel-debuginfo
    The version and release numbers of the above packages must match the version and release numbers of the kernel running on the host system. Run the following command to determine the version and release numbers of the hosts system's kernel:
    ~]$ uname -r
    3.10.0-229.14.1.el7.x86_64
    Note that the kernel-debuginfo package is only available from the Debug channel. Enable the rhel-7-server-debug-rpms repository as described in Section 1.4.1, “Using Red Hat Subscription Management”. For more information on how to get access to debuginfo packages, see https://access.redhat.com/site/solutions/9907.
    To install the required packages with the correct version, use the yum package manager and the output of the uname command. For example, to install the correct version of the kernel package, run the following command as root:
    ~]# yum install -y kernel-$(uname -r)
  3. Save the container to a reusable image by executing the docker commit command. For example, to save the custom-built SystemTap container:
    ~]$ docker commit devtoolset-4-systemtap-$(uname -r)