Containers in Torizon OS

From RidgeRun Developer Wiki





Follow Us On Twitter LinkedIn Email Share this page



Preferred Partner Logo 3



Introduction

Torizon OS uses containers as the main mechanism to install and run application software. Instead of installing software directly into the operating system, applications and tools are packaged into containers that run on top of the base system using Docker.

This approach provides several advantages:

  • Isolation between applications
  • Simplified deployment and updates
  • Reproducible environments across development and production devices

This section introduces the most common ways to install and run software using containers on Torizon OS.

Container Approaches

There are several ways to run software inside containers depending on the requirements of your application. The most common approaches are:

  • Using Debian Containers for Torizon
  • Running pre-built containers
  • Using other base container images
  • Creating a container from scratch

It is also common to combine multiple containers in a system. For example, one container may run a web server while another container runs a data processing application.

The following sections describe each approach.

Debian Containers for Torizon

Debian Containers for Torizon are maintained by Toradex and built specifically for their hardware platforms. They include the necessary configuration and permissions for accessing hardware resources such as graphics acceleration and peripherals.

These containers are based on Debian and allow installing software using the Debian package manager.

Example Dockerfile installing the `sl` package:

FROM torizon/debian:4

RUN apt update && \
    apt upgrade -y && \
    apt install -y sl && \
    apt-get clean && \
    apt-get autoremove -y && \
    rm -rf /var/lib/apt/lists/*

CMD ["/usr/games/sl"]

Build and run the container:

docker build -t steam-locomotive:3 .

You should an output ending with the following:

Step 3/3 : CMD ["/usr/games/sl"]                                                           
 ---> Running in 577ef09638c3                                                              
 ---> Removed intermediate container 577ef09638c3                                          
 ---> c9cac2647a43                                                                         
Successfully built c9cac2647a43                                                            
Successfully tagged steam-locomotive:3

If that is the case, run the image.

docker run --rm -it steam-locomotive:3

You should see a gray screen with moving text simulating a locomotive.

This approach is recommended when developing applications for Torizon OS because it provides good hardware compatibility and easy software installation using Debian packages.

Pre-built Containers

Many popular applications are already distributed as container images in public registries such as Docker Hub.

These containers can be used directly without modification. They are suitable for running services such as web servers, databases, or development tools.

Example: running the official Nginx web server container.

docker run --name some-nginx -d -p 80:80 nginx

You may see an output like the following:

torizon@verdin-imx95-12594515:~$ docker run --name some-nginx -d -p 80:80 nginx 
4d3be12b9a6e8ce5c0a85d8198cc515c03bde46afae9f23134e0313a2e85ed11
torizon@verdin-imx95-12594515:~$

After starting the container, open a web browser and navigate to:

http://<board-ip>

You should see the default Nginx welcome page.

When using development tools such as the Torizon IDE Extension, pre-built containers can also be added to a project through a Docker Compose configuration.

Other Base Containers

Containers can also be built using other Linux distributions such as Alpine, Ubuntu, or Fedora.

These containers are not maintained by Toradex but may be useful when specific libraries or software versions are required.

Example using an Alpine Linux container:

FROM alpine:3
RUN apk add --no-cache fortune
CMD ["/usr/bin/fortune"]

Build and run the container:

docker build -t fortune:3 .
docker run --rm -it fortune:3

Everytime you run this container, you get a phrase as in a fortune cookie:

Nostalgia isn't what it used to be.
I have made mistakes but I have never made the
mistake of claiming that I have never made one.
                -- James Gordon Bennett

Alpine containers are often used because of their small size, which can reduce storage usage on embedded systems.

Creating a Container from Scratch

Containers can also be created from an empty filesystem using the `scratch` base image. This allows creating very small containers containing only the required application and dependencies.

The following example builds a statically compiled C application and copies it into a minimal runtime container.

# Build stage
FROM alpine:3 AS build

WORKDIR /app
RUN apk add --no-cache build-base

RUN printf '#include <stdio.h>\n int main(){ printf("Hello World"); }' > main.c
RUN gcc -static -o hello main.c

# Runtime container
FROM scratch
COPY --from=build /app/hello /app/hello

CMD ["/app/hello"]

Build and run the container:

docker build -t hello:3 .
docker run --rm -it hello:3

The output should be a hello world:

Hello World

This approach offers the smallest possible container size and greater control over installed software, but requires more development effort.