Search by Tags

Configure Build Environment for Torizon Containers

 

Article updated at 12 Feb 2021
Compare with Revision




Select the version of your OS from the tabs below. If you don't know the version you are using, run the command cat /etc/os-release or cat /etc/issue on the board.



Remember that you can always refer to the Torizon Documentation, there you can find a lot of relevant articles that might help you in the application development.

Torizon 5.0.0

Introduction

Torizon supports the docker runtime and this will allow you to run your applications inside containers. It is possible to build and configure containers directly on the target. This works for quick tests or prototypes but is hardly suitable for projects that need to be maintained over time.

In this case, you should define the configuration steps required to initialize your container (installing packages, changing configuration files, adding application-specific content) in a Dockerfile, and use it to build the container on your development machine.

To be able to build containers that can run on a different processor architecture (your development machine will likely use an x86/x64 processor while Toradex's modules have Arm SOCs) you will need to correctly configure the docker environment.

This article complies to the Typographic Conventions for Torizon Documentation.

Prerequisites

  • Windows or Linux host PC for development.

Note: Instructions for Linux machines focus on Debian-based distros.

Windows

Follow the steps to configure your development environment on Windows.

Install the Windows Subsystem for Linux (WSL2)

To obtain the Linux subsystem, please refer to the Microsoft instructions. After following all the steps, reboot your machine.

Warning: WSL2 requires Windows 10, updated to version 2004 (also known as the Windows 10 May 2020 Update) or higher.

  • WSL Setup

You may want to install Windows Terminal from the Microsoft Store to improve your experience using wsl.

Open the Microsoft Store and install a distro. We recommend Ubuntu 20.04 LTS. When the process ends, open CMD and run the following command:

$ wsl

It will ask for your username and password, write it. After setting up your credentials, run the command below to see some information about the distro:

$ wslfetch

  • Wsl output

    Wslfetch output

After evaluating the Windows Subsystem for Linux works, install rsync and ssh from the Linux prompt:

$ sudo apt-get update && sudo apt-get install rsync ssh

Check if Ubuntu 20.04 LTS is the default wsl distro on your system by running the command below:

$ wsl -l -v

  • wsl -l -v output

    wsl -l -v output

Your default distro is represented by the *. If your output is similar to the one above (docker-desktop or another distro being the default), make Ubuntu default distribution by typing the following command:

$ wsl -s Ubuntu-20.04

  • wsl -s Ubuntu-20.04 output

    wsl -s Ubuntu-20.04 output

Using VS Code and Torizon IDE Extension on Windows

The Torizon IDE Extension is designed to be used with a Visual Studio Code running locally on Windows and not inside WSL. Therefore, installing Visual Studio Code Torizon IDE Extension inside WSL may result in unexpected bugs and behaviors from the extension.

The image below shows how VS Code Extensions Manager looks like when VS Code is running inside WSL. It is possible to observe that it has two places where the Torizon IDE Extension can be installed, local and WSL. If the extension is installed the WSL location unexpected bugs and behaviors may happen. If it has just one location it means that VS Code is running on the Windows machine, so the extenstion can be correctly installed from there.


  • Extensions appearance for VS Code running inside WSL

    Extensions appearance for VS Code running inside WSL

Install Docker

Access the Docker for Windows page on the official Docker documentation and go to Install Docker Desktop for Windows. From here you will be redirected to Docker Hub, where you can finally download Docker for Windows.

Recommended Docker Configuration

Attention: if you skip this step, things will break when you use the Visual Studio Extension For Torizon or the Visual Studio Code Extension for Torizon.

Since it is enabled by default on Docker Desktop for Windows, you must disable it by following the instruction from the Docker Desktop release notes. In summary, open the Settings, go to the Docker Engine tab and change the buildkit property to false, also check if experimental is set to false.


  • Disable Docker Buildkit

    Disable Docker Buildkit

Linux

Follow the steps to configure your development environment on Linux.

Install Docker

The release of Docker provided by some distribution is not up to date, to be sure that you install docker in the correct way please go to docker website and follow instructions for your OS/distribution.

You don't need to install the experimental version, but keeping the docker setup up to date would help you avoid issues that have been already fixed in the latest stable release.

You will need to add your user to the docker group to allow you to run docker client without needing root privileges.

The specific command used to perform this operation may be different, depending on your distribution.

On Debian-based distributions, like Ubuntu, you should use the addgroup command:

$ sudo addgroup <your user name> docker

You will have to logout and login to see the change applied. You can list the groups that contain your user account by typing groups in the shell.

Enable Arm emulation

Arm emulation makes it possible to run Arm instructions on Intel x86-64 architectures. That is, you can run binaries compiled for the Arm instruction set on an x86 computer.

To enable this emulation to be used with Docker, run the following command:

Note: use the same command for Windows (Docker Desktop Hyper-V VM or Docker Desktop using WSL 2 as backend) and Linux distributions.

$ docker run --rm -it --privileged torizon/binfmt

Warning: This operation will run a privileged container, it will run for the time required to enable Arm emulation using binfmt. It should be a safe operation. Note: Enabling Arm emulation through this method is NOT persistent. After reboots, you have to run this command again to re-enable Arm emulation.

This command will install and register the interpreters that will know how to run the arm32v7 and arm64v8 instructions on your Intel x86 development PC. This use the Kernel Linux support for miscellaneous binary formats feature.

To test whether the interpreters have been successfully installed, run the commands:

Test arm32v7

$ docker run --rm -it arm32v7/debian arch

The return must be:

armv7l

Test arm64v8

$ docker run --rm -it arm64v8/debian arch

The return must be:

aarch64

Torizon 4.0.0

Introduction

Torizon supports the docker runtime and this will allow you to run your applications inside containers. It is possible to build and configure containers directly on the target. This works for quick tests or prototypes but is hardly suitable for projects that need to be maintained over time.

In this case, you should define the configuration steps required to initialize your container (installing packages, changing configuration files, adding application-specific content) in a Dockerfile, and use it to build the container on your development machine.

To be able to build containers that can run on a different processor architecture (your development machine will likely use an x86/x64 processor while Toradex's modules have Arm SOCs) you will need to correctly configure the docker environment.

This article complies to the Typographic Conventions for Torizon Documentation.

Prerequisites

  • Windows or Linux host PC for development.

Note: Instructions for Linux machines focus on Debian-based distros.

Install Docker

Here are instructions on how to set up Docker in your computer - which is usually called development PC or simply host.

Windows

Access the Docker for Windows page on the official Docker documentation and go to Install Docker Desktop for Windows. From here you will be redirected to Docker Hub, where you can finally download Docker for Windows.

Linux

The release of Docker provided by some distribution is not up to date, to be sure that you install docker in the correct way please go to docker website and follow instructions for your OS/distribution.

You don't need to install the experimental version, but keeping the docker setup up to date would help you avoid issues that have been already fixed in the latest stable release.

You will need to add your user to the docker group to allow you to run docker client without needing root privileges.

The specific command used to perform this operation may be different, depending on your distribution.

On Debian-based distributions, like Ubuntu, you should use the addgroup command:

$ sudo addgroup <your user name> docker

You will have to logout and login to see the change applied. You can list the groups that contain your user account by typing groups in the shell.

Enable Arm emulation

Arm emulation makes it possible to run Arm instructions on Intel x86-64 architectures. That is, you can run binaries compiled for the Arm instruction set on an x86 computer.

To enable this emulation to be used with Docker, run the following command:

Note: use the same command for Windows (Docker Desktop Hyper-V VM or Docker Desktop using WSL 2 as backend) and Linux distributions.

$ docker run --rm -it --privileged torizon/binfmt

Warning: This operation will run a privileged container, it will run for the time required to enable Arm emulation using binfmt. It should be a safe operation. Note: Enabling Arm emulation through this method is NOT persistent. After reboots, you have to run this command again to re-enable Arm emulation.

This command will install and register the interpreters that will know how to run the arm32v7 and arm64v8 instructions on your Intel x86 development PC. This use the Kernel Linux support for miscellaneous binary formats feature.

To test wheter the interpreters have been successfully installed, run the commands:

Test arm32v7

$ docker run --rm -it arm32v7/debian arch

The return must be:

armv7l

Test arm64v8

$ docker run --rm -it arm64v8/debian arch

The return must be:

aarch64