Skip to main content

Writing your First Dockerfile


When it comes to Linux development, it is possible to choose several IDEs, workflows and programming languages for development. Aiming to simplify your development experience Toradex provides TorizonCore IDE integration with Visual Studio Code for Windows and Linux PCs, and Visual Studio for Windows PCs.

In this module you will:

  • Use the Visual Studio IDE.
  • Cross-compile your application using the Torizon Extension for Visual Studio.
  • Deploy it to the target module and debug it remotely from your development PC.

Support for a more complex workflow on Visual Studio will be presented to you at the end of the quickstart guide, as well as support for other programming languages on Visual Studio Code. If you have a Linux PC for development, you can also try the quickstart guide for Torizon with Linux selected as Development PC OS.

Typographic Conventions

Throughout the Toradex documentation, the following typographic conventions are used:

$ (dollar sign) Command in the host computer (e.g. your PC)

$ Command in your PC

$$ (double dollar sign) Command in a container in the host computer (e.g. your PC)

$$ Command inside a container in your PC

# (hashtag) Command in the target device/board (e.g. Linux terminal)

# Command in the target board, e.g. Colibri iMX6

## (double hashtag) Command inside a container in the target device (Torizon)

## Command inside a container in Torizon

> (greater-than sign) Command in the bootloader (e.g. U-Boot console)

> Command in the Bootloader

No symbol: Command output

$ Command waiting for output


For this lesson:

  • Docker downloaded and running. If you are not sure, please refer to the previous lessons.

Step 1

Step 2

Step 3

Step 4


What is a Dockerfile?

A Dockerfile is a text file containing instructions for building a Docker image. At the Docker Documentation there is a lot of information about them, and guidelines which we will use in this article.

This is a sample Dockerfile:

# Points to a base, pre-existing image. In this case, it points to the [ubuntu container](, tagged with version 18.04;
FROM ubuntu:18.04

# Copies files from the host machine to the created image;
COPY /root

# Runs commands as root on the created image;
RUN apt update && apt install nano

# Specifies what command will run when a new container is created based on the resulting image.
CMD [ "./" ]

Be aware that the resulting image will be compatible with the host system architecture only, by default.

What does the created Dockerfile do?
  1. The FROM command shows where to get the base of our Docker image. If you want to cross-build it, make sure to choose a pre-built image for ARM.
  2. We run some commands to install packages from Debian feeds, to test if the cross-build really works.
  3. Starts the X server, so we can have a graphical user interface.
Can I have multiple Dockerfiles with different names?

Yes, you can. The command docker build accepts a parameter for specifying a Dockerfile with a name different from the standard one, which enables you to have separate Dockerfiles for development vs. production, or for different base images, for instance, Python vs. Python slim or the latest stable vs. bleeding edge release of a distro. For example for a Dockerfile named foo.Dockerfile:

$ docker build -f foo.Dockerfile .

Any name is accepted, though you may consider using a standard. For instance, some Visual Studio Code plugins automatically have syntax highlight for any files with .Dockerfile extension, such as prod.Dockerfile and dev.Dockerfile.

Send Feedback!