Creating a Docker image with RTI Connext DDS

This article assumes familiarity with Docker.  For instance, you should know the difference between containers and images, and the purpose of a Dockerfile. If not, then visit www.docker.com and get up to speed on Docker basics before reading further.

Introduction

In this example, we’ll create a Docker image that can build RTI Connext DDS applications. We’ll use Ubuntu 16.04 (x64) for the target operating system and assume that the host is also using a Linux OS*. We’ll create an image named dds-build. It will be relatively large because it holds the RTI Connext DDS installation and the Linux build tools.

*The host can use a different version of a Linux, Windows, or Mac operating system.

Creating the Build Image

Note: If you are using an evaluation version of RTI Connext DDS, you must follow a different process for creating your DDS build image. See Variation: Evals, below.

We’ll create a Docker image, named dds-build, that can build DDS applications. This image needs to include the DDS installation as well as build tools like make and gcc. The goal is to create an image that is capable of building any DDS application. When you use  dds-build to compile your RTI Connext DDS application, you will need to mount your source-code directory as a volume in the Docker container. This process is explained in a separate article.

We’ll begin by creating a directory named mybuild (or whatever you prefer).  This directory will hold the build context for creating the image:

$ mkdir mybuild

Now download the RTI Connext DDS host and target installation files and copy them to mybuild.  In this example, we use the following files:

rti_connext_dds-5.3.0-pro-host-x64Linux.run
rti_connext_dds-5.3.0-pro-target-x64Linux3gcc5.4.0.rtipkg

We now need to tell Docker what to do with these files.  Create a file named Dockerfile in mybuild, with the following content:

# Ubuntu 16.04 is supported by RTI Connext DDS 5.3.0
# Use Docker's multi-stage build capability to create an image that
# contains only Ubuntu and the fully-installed RTI Connext distribution
FROM ubuntu:16.04 as dds_install

# /app will hold our installation files
WORKDIR /app

# Copy the installation files into the image
COPY rti_connext_dds-5.3.0-pro-host-x64Linux.run \
     rti_connext_dds-5.3.0-pro-target-x64Linux3gcc5.4.0.rtipkg \
     ./

# Run the host package installer
RUN chmod +x rti_connext_dds-5.3.0-pro-host-x64Linux.run && \
    ./rti_connext_dds-5.3.0-pro-host-x64Linux.run --mode unattended

# Run the target package installer
RUN /opt/rti_connext_dds-5.3.0/bin/rtipkginstall \
    -u rti_connext_dds-5.3.0-pro-target-x64Linux3gcc5.4.0.rtipkg

# Start from a fresh image
FROM ubuntu:16.04

# Copy the RTI Connext DDS installation from the image created above
COPY --from=dds_install \
     /opt/rti_connext_dds-5.3.0 /opt/rti_connext_dds-5.3.0

# Set up the DDS execution environment
ENV NDDSHOME /opt/rti_connext_dds-5.3.0
ENV PATH $PATH:$NDDSHOME/bin

# Install the license file
COPY rti_license.dat /opt/rti_connext_dds-5.3.0
 
# Install build tools
RUN apt-get update && apt-get -y install gcc g++ make

The mybuild directory should now contain these files:

Dockerfile
rti_connext_dds-5.3.0-pro-host-x64Linux.run
rti_connext_dds-5.3.0-pro-target-x64Linux3gcc5.4.0.rtipkg
rti_license.dat 

We’re now ready to actually build the first Docker image. Use these commands to build the image:

$ cd mybuild
$ docker build -t dds-build .

When Docker finishes running, your local Docker registry will have an image named dds-build.  You can confirm this by running:

$ docker image ls
REPOSITORY  TAG         IMAGE ID        CREATED          SIZE
dds-build   latest      f39efa68fcdf    16 seconds ago   1.37GB
$

Congratulations! You have created a Docker image that can be used to build DDS applications.

Variation: Evals

If you are using an evaluation version of RTI Connext DDS, you must follow a different process for creating your DDS build image.  This is because the evaluation installer does not support unattended mode.

In order to use the evaluation version, first install it locally on your operating system.  (You must use the same operating system that will be used in the Docker DDS build image.)  For example, create a directory named mybuild_eval and install RTI Connext DDS in this directory, so that the installation path is mybuild_eval/rti_connext_dds-5.3.0.  Then add the following Dockerfile to mybuild_eval:

# Ubuntu 16.04 is supported by RTI Connext DDS 5.3.0
FROM ubuntu:16.04

# Copy the RTI Connext DDS installation from build context
COPY rti_connext_dds-5.3.0 /opt/rti_connext_dds-5.3.0/

# Set up the DDS execution environment
ENV NDDSHOME /opt/rti_connext_dds-5.3.0
ENV PATH $PATH:$NDDSHOME/bin

# Install the license file
COPY rti_license.dat /opt/rti_connext_dds-5.3.0 

# Install the necessary build tools
RUN apt-get update && apt-get -y install gcc g++ make

Run the following command to build the image:

$ cd mybuild_eval
$ docker build -t dds-build-eval .

Then you can use the dds-build-eval image just as you would use the dds-build image described in Creating the Build Image, above.

Other Topics

For more examples of how to use Docker with RTI Connext DDS, search for “docker” at https://community.rti.com or https://blogs.rti.com.

Keywords: