Docker Configuration

On the Collection Editor page, scroll down to find the “Docker Container” section. This is where most of the setup takes place.

Uploading the Dockerfile

To upload your Dockerfile, compress it into a tarball first. In the terminal, move to the directory where the Dockerfile is present.

Note: The Dockerfile needs to be at the root of this directory.

The following command can be used to create a tarball:

tar -czvf tarball.tar.gz Dockerfile

You can rename tarball to whatever you prefer. Make sure the tarball extension is tar.gz.

Building the Docker Image

Once the file has been uploaded, click on the Save button in the top-right corner to build the image. This step may take a while, especially if the image is large. You will see the following loading screen:

widget

If the image is built successfully, a message will be prompted on the screen:

widget

If there is an error in the Dockerfile, the image building process will fail. This can happen due to a number of reasons. To check the details of the issue, click the “Download Build Logs” button:

widget

You will be displayed a text file with all the details of where the error occurred.

Creating a Docker Job

With the Docker image built, the next step is to add a Docker job for the image. The Docker job is responsible for creating the actual container. Hence, it is very important to get this step right.

To create a job, click the “Add Job” button:

widget

A menu will be displayed where you can set the details of the job:

Select Docker Job Type

You can use this to select your desired job type. You can choose from the following options depending upon your needs:

  • Default
  • Live
  • GUI

We’ll discuss Job Types in detail later on.

Job Name

This is simply the name of the job. This name will be used to select the job in a code widget or SPA (more on this later).

Input File Name

This is the file which the container will run. The input file is used in the Code widget to determine which file has to be executed. By default, the main file in the Code widget is called main. However, if you provide a different name in the Input File Name field of the job, that file will replace main.

For example, we may set the input file name as prog.py for a Python container. This change will be reflected in the code widget:

Do not worry if this feels confusing at the moment. We will see it in action in the upcoming lesson.

Run Script

This script will be run inside your container in order to execute the input file. Think of it as a set of commands that are run in the terminal of your container.

So, for a C++17 file called main.cpp, the Run Script would be:

g++ -std=c++1z main.cpp;
./a.out

The Run Script is executed when we press RUN in the Code or SPA widget (more on this in the upcoming lessons).

Multiple Docker Jobs

Keep in mind that you can make as many jobs as you require. You may want the container to perform different tasks (specified in the Run Script) in each job. This allows you to make a single Docker image and perform various jobs in the container.

Docker Use-cases

Now that we are familiar with the image building process and the Docker job, we can start using them to create our environments. There are five main scenarios where Docker can be used:

  • Code widget
  • SPA widget
  • Terminal widget
  • Live App widget
  • GUI App widget

Each use-case has a different purpose, and we will go through them one by one.