Configure Build Environment for Torizon Containers
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.
- Windows or Linux host PC for development.
Instructions for Linux machines focus on Debian-based distros.
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.
WSL2 requires Windows 10, updated to version 2004 (also known as the Windows 10 May 2020 Update) or higher.
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:
It will ask for your
password, write it. After setting up your credentials, run the command below to see some information about the distro:
After evaluating the Windows Subsystem for Linux works, install
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
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
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
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
false, also check if
experimental is set to false.
Follow the steps to configure your development environment on Linux.
Install 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.
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
$ 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:
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
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:
$ docker run --rm -it arm32v7/debian arch
The return must be:
$ docker run --rm -it arm64v8/debian arch
The return must be: