How to autorun an application with Torizon?

Hello, i am using Verdin IMX8M mini on my personnal carrier board and i am almost done with the programming part, i just want to Autorun my application container when the SoM start.

I found this article :
https://developer.toradex.com/torizon/application-development/working-with-containers/how-to-autorun-an-application-with-torizoncore/

and i created the docker-compose directory with the following command :

sudo mkdir -p /var/sota/storage/docker-compose

then i pasted my application docker-compose.yml file in it.

cp /home/torizon/docker-compose.yml /var/sota/storage/docker-compose

i checked with cat that my docker compose file was in the docker-compose directory and it’s seems okay.

But when i try to poweroff and on my SoM, the container doesn’t start automatically.

Thank your for your help !

Best regards

Greetings @autolab,

We have a simple systemd service that just runs /usr/bin/docker-compose -p torizon up -d --remove-orphans on /var/sota/storage/docker-compose/docker-compose.yml. If you do this manually yourself does it work?

What does your docker-compose.yml look like, if you can share it. Also what version of Torizon OS are you running here?

Best Regards,
Jeremias

1 Like

Hello, sorry for the delay,

so there is my docker-compose.yml:

version: "3.9"
services:
  quickstart-debug:
    privileged: true
    build:
      context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/quickstart-debug:${TAG}
    ports:
      - 6502:6502
      - 6512:6512
      - 4840:4840
    volumes:
      - type: bind
        source: /dev
        target: /dev
        read_only: false
      - type: bind
        source: /sys
        target: /sys
        read_only: false
    # Add device access rights through cgroup...
    device_cgroup_rules: 
      - "c 254:* rmw"
      - "c 248:* rmw"
    devices:
      - "/dev/spidev1.0"

i am using the last version of Torizon OS because i received my SoM last week.

We have a simple systemd service that just runs /usr/bin/docker-compose -p torizon up -d --remove-orphans on /var/sota/storage/docker-compose/docker-compose.yml. If you do this manually yourself does it work?

I am sorry, i don’t know how to do this, can you give me more informations?

Thank you

Best regards

If i try to run in my SoM via SSH

torizon@verdin-imx8mm-xxx:~$ /usr/bin/docker-compose -p torizon up -d --remove-orphans

i get the error:

WARN[0000] The "LOCAL_REGISTRY" variable is not set. Defaulting to a blank string.
WARN[0000] The "TAG" variable is not set. Defaulting to a blank string.
Error response from daemon: no such image: :5002/quickstart-debug:: invalid reference format

also if i run :

systemctl list-units --type=service

i can see the service "docker-compose.service " in failed status

docker-compose.service                                                     loaded failed     failed        Docker Compose service

To clarify the situation, i am developing with torizon in VS code, as this tutorial show:
quickstart guide

and if i run it with VS code everything is working fine, but now i need it to automatically start when my SoM is powered on.

Wait you’re trying to autorun the debug container? That container does not make sense to run on it’s own without VSCode. That container just starts ssh to communicate to VSCode for debugging purposes it doesn’t run your application on it’s own. Also look at the image in your docker-compose.yml: image: ${LOCAL_REGISTRY}:5002/quickstart-debug:${TAG} these variables are reliant on VSCode and the local registry that is running on your PC. The debug container is not meant to be used in the way you’re using it here.

The proper way here would be to build the release version of the container, push it to a container image registry then point your compose file at that. See the article here for more info: Build and Push Applications | Toradex Developer Center

You don’t have to do the parts involving Torizon cloud you can just read the parts about creating the release image.

Best Regards,
Jeremias

Hello,
Thanks for the response it was helpful.

I’m sorry for the misunderstanding.

I used the task runner to push realase arm64. If I understood correctly, put the image and the production container on my SOM.

the container works as it should, it runs an OPC UA server which works when I test it.

Now I would like to create my production image with “create production image” (the rest of the guide) in order to put my image in the docker hub to be able to pull it onto all my SoM.

I used “create-production-images” in the task runner and it worked.

I used docker desktop to push the created image to the docker hub.

I can pull it without problem on my “test” SoM and run it.

The problem is that the container does not seem to have the rights to access for example the SPI or PWM whereas with the image generated in the previous step, I did not have this problem.

Here is my modified Dockerfile:

# ARGUMENTS --------------------------------------------------------------------
##
# Board architecture
##
ARG IMAGE_ARCH=
# For armv7 use:
#ARG IMAGE_ARCH=arm

##
# Base container version
##
ARG BASE_VERSION=3.0.8-bookworm

ARG APP_ROOT=

FROM --platform=linux/${IMAGE_ARCH} \
    torizon/debian:${BASE_VERSION} AS Deploy

ARG IMAGE_ARCH
ARG APP_EXECUTABLE
ARG APP_ROOT

# your regular RUN statements here
# Install required packages
RUN apt-get -q -y update && \
    apt-get -q -y install \
    python3-minimal \
    python3-pip \
    python3-venv \
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    # __torizon_packages_prod_start__
	libgpiod-dev:arm64 \
	gpiod:arm64 \
    # __torizon_packages_prod_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    && apt-get clean && apt-get autoremove && \
    rm -rf /var/lib/apt/lists/*

# Allow the user torizon use GPIOs and SPI
RUN usermod -a -G gpio root

# Allow user "root" to use PWM
RUN usermod -a -G pwm root

RUN usermod -a -G spidev root

# Create virtualenv
RUN python3 -m venv ${APP_ROOT}/.venv --system-site-packages
RUN apt-get update && apt-get install -y build-essential python3-dev

# Install pip packages on venv
COPY requirements-release.txt /requirements-release.txt
RUN . ${APP_ROOT}/.venv/bin/activate && \
    pip3 install --upgrade pip && pip3 install --break-system-packages -r requirements-release.txt && \
    pip3 install spidev && \
    rm requirements-release.txt

RUN apt-get -q -y install \
    python3-libgpiod
# copy the source code
COPY /src ${APP_ROOT}/src

WORKDIR ${APP_ROOT}

ENV APP_ROOT=${APP_ROOT}
# Activate and run the code
CMD . ${APP_ROOT}/.venv/bin/activate && python3 src/main.py --no-sandbox

As well as my docker-compose.yml also modified:

version: "3.9"
services:
  quickstart-debug:
    privileged: true
    build:
      context: .
      dockerfile: Dockerfile.debug
    image: ${LOCAL_REGISTRY}:5002/quickstart-debug:${TAG}
    ports:
      - 6502:6502
      - 6512:6512
 
  quickstart:
    privileged: true
    build:
      context: .
      dockerfile: Dockerfile
    image: ${DOCKER_LOGIN}/quickstart:${TAG}
    ports:
      - 6502:6502
      - 6512:6512
      - 4840:4840
    volumes:
      - type: bind
        source: /dev
        target: /dev
        read_only: false
      - type: bind
        source: /sys
        target: /sys
        read_only: false
    # Add device access rights through cgroup...
    device_cgroup_rules: 
      - "c 254:* rmw"
      - "c 248:* rmw"
    devices:
      - "/dev/spidev1.0"

Does i miss something in the configuration ? I used “autolab23” as namespace and “v1.0” as tag for the “create production image”

here is the error i get:

torizon@verdin-imx8mm-xxx:~$ docker run autolab23/quickstart:v1.0
cryptography is not installed, use of crypto disabled
cryptography is not installed, use of crypto disabled
Traceback (most recent call last):
  File "//src/main.py", line 27, in <module>
    spi.open(1, 0)  # bus, device 200 000 /dev/spidev1.0
    ^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory

Well now the problem is you’re just running docker run with no arguments. This just starts your container as is without any extra configurations.

Look at your docker-compose.yml do you see all the extra information besides your container image name? These are arguments that are ran alongside your container. If you are using docker run you must supply these arguments yourself. There is lots of Docker documentation out there on how to translate arguments in docker-compose.yml to docker run arguments.

Otherwise you can just run docker-compose up on your compose file. This invokes your compose file using the arguments defined in the file to start your container as described. Make sure you specifically only start the release/production image and not the debug one in your compose file as it wouldn’t make sense to start both.

Best Regards,
Jeremias

1 Like

Okey thank you for all the answer it was really helpfull !

Best regards

Glad I was able to help clarify!

1 Like