Configure Build Environment for Torizon Containers
Introduction
In this article, you will learn the basic setup of a development environment for Torizon, regardless of your choice of code editor/IDE or revision control system. As applications are integrated into TorizonCore using containers, this setup mainly involves configuring a Docker environment. Here you will find instructions for both Linux and Windows development environments.
Torizon Development Environment
While it is possible to build and configure containers directly on the target for quick tests or prototypes, this approach is generally not suitable for projects that require long-term maintenance.
The recommended workflow for Torizon involves the cross-compilation of containers. In this case, you should define the necessary configuration steps to initialize your container in a Dockerfile and use it to build the container on your host machine:
- Installing packages.
- Changing configuration file.
- Adding application-specific content.
Your development machine will likely use an x86/x64 processor, while Toradex's modules have Arm SOCs. To build containers that can run on a different processor architecture, you have to properly configure the Docker environment according to the instructions presented in this article.
This article complies with the Typographic Conventions for Toradex Documentation.
Prerequisites
Host machine with:
- Windows or Linux OS.
- Visual Studio Code installed.
dangerYou have to install the Visual Studio Code from its Download page. The V2.0 extension will not work with VS Code installed via Snap or Flatpak!
For WSL 2, the Visual Studio Code has to be installed on the Windows side.
Windows
Follow the steps to configure your development environment on Windows.
Install the Windows Subsystem for Linux (WSL 2)
The Windows Subsystem for Linux (WSL) enables the use of most Linux command-line tools, utilities and applications directly on Windows.
WSL2 requires Windows 10, updated to version 2004 (also known as the Windows 10 May 2020 Update) or higher.
Open Powershell as administrator.
Install WSL: use the
wsl --install -d Ubuntu-22.04
command.infoToradex recommends using Ubuntu 22.04. If you are familiar with a different Linux distribution, refer to the WSL documentation to ensure a correct installation, then follow the instructions in the Linux section to install Docker Engine.
Restart your PC.
A WSL terminal will be automatically opened. Do not close it!
Input a username and password: you will use this password when running
sudo
commands in the WSL terminal.Proceed to the Docker engine installation: you will run the commands in the WSL terminal.
How to check the default Linux distribution of WSL
You can check the installed and default distributions of WSL by running the following command in PowerShell:
$ wsl -l -v
For detailed information, refer to the WSL documentation.
Install Docker Engine
As Docker Desktop is licensed under the Docker Subscription Service Agreement, we recommend using Docker Engine.
Install Docker Engine: run the following commands:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
net-tools \
gnome-keyring
$ sudo mkdir -m 0755 -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
After the Docker installation, you need to create the docker group and add your user to it. This is required to run the Docker commands without sudo. In a new terminal from the WSL 2 distro run the following commands.
Create the
docker
group:$ sudo groupadd docker
Add your user to the
docker
group.$ sudo usermod -aG docker $USER
Restart your PC.
Before using Docker commands or the Torizon IDE Extension 2, you need to start the Docker service in a WSL terminal.
Open a WSL terminal: you can search for wsl in the Windows search bar.
Start the Docker service:
$ service docker start
For detailed information, refer to the Docker Engine documentation.
Install the WSL VS Code extension
The Visual Studio Code IDE enables you to work in the WSL filesystem, providing access to the Linux environment directly from Windows. It includes the git revision control system, Docker command line tools, and more.
To install the WSL extension, proceed with the following steps:
Click the
Extensions
icon from the left menu bar in Visual Studio Code.Search for
ms-vscode-remote.remote-wsl
. ClickInstall
.
Linux
Follow the steps to configure your development environment on Linux.
Install Docker Engine
As Docker Desktop is licensed under the Docker Subscription Service Agreement, we recommend using Docker Engine.
Install necessary packages: before installing Docker Engine, install the following packages.
$ sudo apt-get update
$ sudo apt-get install -y \
ssh\
net-tools \
gnome-keyringInstall Docker Engine: The release of Docker provided by some distribution is not up to date. To be sure that you install docker in the correct way, chose the source for your distribution.
Browse from one of those sources if you don't use any of these distributions. If you want to install from binaries, take a look at Install Docker Engine from binaries.
Create the
docker
group: you will need to add your user to the docker group to allow you to run the Docker client without needing root privileges. In a new terminal, run the following commands.$ sudo groupadd docker
Add your user to the
docker
group.$ sudo usermod -aG docker $USER
Restart your PC.
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:
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
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.
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