Start app within the weston-vivante container at boot

Device : iMX8mp
OS: Torizon OS 6.x.x latest.

Hi,
I want to launch my GUI application on boot, for that I created a custom weston-vivante docker image which contains all the libraries as well as my application. When I create a container using that image with `docker run -e ACCEPT_FSL_EULA=1 -d --rm --name=weston --net=host --cap-add CAP_SYS_TTY_CONFIG \

         -v /dev:/dev -v /tmp:/tmp -v /run/udev/:/run/udev/ \
         --device-cgroup-rule='c 4:* rmw' --device-cgroup-rule='c 13:* rmw' \
         --device-cgroup-rule='c 199:* rmw' --device-cgroup-rule='c 226:* rmw' \
         myimagename:mytag --tty=/dev/tty7`

a container is started, then I get into container with docker exec -it container-name /bin/bash , go to directory, run the ./app and application runs fine.

Since I want all this to happen automatically at boot I created yaml file at /var/sota/storage/docker-compose/docker-compose.yml

version: "3.9"
services:
  weston:
    image: torizon/weston${GPU}:3
    container_name: weston-tor
    environment:
      - ACCEPT_FSL_EULA=1
    # Required to get udev events from host udevd via netlink
    network_mode: host
    volumes:
      - type: bind
        source: /tmp
        target: /tmp
      - type: bind
        source: /dev
        target: /dev
      - type: bind
        source: /run/udev
        target: /run/udev
    cap_add:
      - CAP_SYS_TTY_CONFIG
    # Add device access rights through cgroup...
    device_cgroup_rules:
      # ... for tty0
      - "c 4:0 rmw"
      # ... for tty1
      - "c 4:1 rmw"
      # ... for tty7
      - "c 4:7 rmw"
      # ... for /dev/input devices
      - "c 13:* rmw"
      - "c 199:* rmw"
      # ... for /dev/dri devices
      - "c 226:* rmw"

the above file works fine but as soon as I try to add command variable or entrypoint variable and try to launch even weston-flower , the container doesn’t starts.
I also, tried to add cmd variable in the dockerfile while creating container image, the container starts but app is not launched.
What can I do in this case.

Greetings @Sudharshan,

If I understand correctly you’re trying to use the Weston container to launch another process? If so then this does not work like you think it will.

The weston container already has an entrypoint. That is the process that starts the Weston compositor. If you overwrite this process with another one, then weston won’t start.

What you should do is launch weston as one container to start and manage the Weston process. Then start a completely different container that then launches the graphical app you want. Look at the example here: Debian Containers for Torizon | Toradex Developer Center

We launch one container for the Weston compositor. Then we launch a 2nd separate container for weston-terminal.

Best Regards,
Jeremias

Hi @jeremias.tx ,

As I’m on iMX8mp, when I run the first command to start weston, the compositor is up, but when I create a second container wayland-app , firstly the container is just not created with --rm flag , without -rm flag it gets created but exits immediately , also the weston-terminal doesn’t starts since the wayland-app container exits with

torizon@verdin-imx8mp-14753765:~/final$ docker logs wayland-app 
Switching VT tty7 to text mode if currently in graphics mode
Couldn't open /dev/tty7

I see the portainers runs the way you are telling , even when I create application with vscode templates the weston container is separate and application container is separate. But these two commands when running subsequently doesn’t works for me.
And If I’m running a GTK application by having separate containers, one container would be weston vivante for compositor. The second container where my app will reside shall be based on which container , debian or wayland?

Regards

Hi @Sudharshan ,

Kindly share your docker run command without -d flag, alos share any logs you get to further check.
additionally please share output of below commands

sudo tdx-info

docker ps 
docker ps -a
docker ps -q
docker images

And If I’m running a GTK application by having separate containers, one container would be weston vivante for compositor. The second container where my app will reside shall be based on which container , debian or wayland?

I believe you can use Debian based Docker image with proper gtk packages to run gtk application with wayland backend.

Best Regards
Ritesh Kumar

Hi @ritesh.tx
PFB

Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.129-6.4.0+git.67c3153d20ff #1-TorizonCore SMP PREEMPT Wed Sep 27 12:30:36 UTC 2023
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/460c0c1dde52ce6a4fd14e6ff7399ad1c879175a9ffa047acbb97523d9376591/0
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.4.0-build.5
Hostname:                 verdin-imx8mp-14753765
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus on Verdin Development Board
Toradex version:          0063 V1.1A
Serial number:            14753765
Processor arch:           aarch64
------------------------------------------------------------
torizon@verdin-imx8mp-14753765:~$ docker ps 
CONTAINER ID   IMAGE                      COMMAND                  CREATED       STATUS             PORTS     NAMES
f19a28e1a213   torizon/weston-vivante:3   "/usr/bin/entry.sh -…"   4 weeks ago   Up About an hour             weston

torizon@verdin-imx8mp-14753765:~$ docker ps -a
CONTAINER ID   IMAGE                      COMMAND                  CREATED          STATUS                        PORTS     NAMES
d405630118f1   mywaylandapp:1.0           "/bin/bash"              17 minutes ago   Exited (255) 12 minutes ago             xenodochial_hypatia
4b636991758d   torizon/weston-vivante:3   "/usr/bin/entry.sh -…"   6 days ago       Exited (1) 44 hours ago                 weston1
f19a28e1a213   torizon/weston-vivante:3   "/usr/bin/entry.sh -…"   4 weeks ago      Up About an hour                        weston
torizon@verdin-imx8mp-14753765:~$ docker ps -q
f19a28e1a213
torizon@verdin-imx8mp-14753765:~$ docker images
REPOSITORY               TAG              IMAGE ID       CREATED             SIZE
mywaylandapp             1.0              b2aeec4771d2   About an hour ago   407MB
kiwi                     3                983319ae6119   18 hours ago        760MB
torizon/weston           3                ca8609dea4a7   44 hours ago        364MB
torizon/debian           3.3-bookworm     786f4bbef578   44 hours ago        115MB
torizon/weston-vivante   3                b9630cbc2309   2 months ago        515MB
torizon/weston-vivante   3.2              b9630cbc2309   2 months ago        515MB
torizon/debian           3.2.1-bookworm   470107e5e0f4   2 months ago        115MB
torizon/weston-vivante   2                eb17fa1e613f   18 months ago       424MB

Created mywayland app with below dockerfile

torizon@verdin-imx8mp-14753765:~/bla$ cat Dockerfile
# Specify the target architecture
ARG IMAGE_ARCH=linux/arm64

# Specify the base image name
ARG BASE_NAME=torizon/debian

# Specify the image tag
ARG IMAGE_TAG=3.3-bookworm

# Specify the Docker registry
ARG DOCKER_REGISTRY=torizon

# Use multi-stage build and specify the target platform
FROM --platform=$IMAGE_ARCH $BASE_NAME:$IMAGE_TAG AS base

# Install aptitude
RUN apt-get update && \
    apt-get install -y aptitude

# Install unicode
RUN apt-get install -y libicu-dev

# Accept all unmet dependencies confirmation thrown by aptitude
RUN aptitude -y install libwxgtk3.2-1

# Copy your application (assuming it's in the current directory)
COPY path/home/torizon/dir

# Set the working directory
WORKDIR /home/torizon/dir


docker run -e ACCEPT_FSL_EULA=1 -d --rm --name=wayland-app  \
             -v /dev/dri:/dev/dri -v /dev/galcore:/dev/galcore -v /tmp:/tmp \
             --device-cgroup-rule='c 199:* rmw' --device-cgroup-rule='c 226:* rmw' \
             mywaylandapp:1.0 ./build/app

When I run a container from above image, with above command ,my app fails to start following log

torizon@verdin-imx8mp-14753765:~/bla$ docker logs wayland-app 
12:30:41: Error: Unable to initialize GTK+, is DISPLAY set properly?

Please ignore the directory I’ve changes it for posting here. Its just that my second container cannot use weston for some reason when I’m trying to run it.

Regards

Hi @jeremias.tx ,
I tried the example given here. It works in one go and runs the example application.
I modified the dockerfile as per my requirement, installed the required, libraries , and tried to up with docker compose yet only the weston container run, the application container exits with below message.

torizon@verdin-imx8mp-14753765:~/ex$ docker logs ex-pysimplegui-1 
17:10:22: Error: Unable to initialize GTK+, is DISPLAY set properly?

Is there any additional configuration needed to run GTK application? from different container.

I also tried torizon-samples/opencv/docker-compose.yaml at bookworm · toradex/torizon-samples · GitHub as it uses GTK.
that too fails with below logs

[+] Running 3/3
 ✔ Network opencv_default             Created                                                                                                            0.1s 
 ✔ Container opencv-weston-1          Created                                                                                                            2.4s 
 ✔ Container opencv-opencv-example-1  Created                                                                                                            0.1s 
Attaching to opencv-opencv-example-1, opencv-weston-1
opencv-weston-1 exited with code 1
opencv-opencv-example-1 exited with code 1
torizon@verdin-imx8mp-14753765:~/opencv$ docker logs opencv-opencv-example-1
Traceback (most recent call last):
  File "/home/torizon/opencv-example.py", line 6, in <module>
    cv2.imshow('image',img)
cv2.error: OpenCV(4.6.0) ./modules/highgui/src/window_gtk.cpp:635: error: (-2:Unspecified error) Can't initialize GTK backend in function 'cvInitSystem'

torizon@verdin-imx8mp-14753765:~/opencv$ docker logs opencv-weston-1        
Switching VT tty1 to text mode if currently in graphics mode
Couldn't open /dev/tty1
torizon@verdin-imx8mp-14753765:~/opencv$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
torizon@verdin-imx8mp-14753765:~/opencv$ docker start weston1
weston1
torizon@verdin-imx8mp-14753765:~/opencv$ 

Regards

I modified the dockerfile as per my requirement, installed the required, libraries , and tried to up with docker compose yet only the weston container run, the application container exits with below message.

Well it’s hard to say what the issue here is exactly since it’s based on your modifications.

I also tried torizon-samples/opencv/docker-compose.yaml at bookworm · toradex/torizon-samples · GitHub as it uses GTK.
that too fails with below logs

I can confirm this sample is outdated.

Perhaps you can take a look at our templates repository that is used by our VSCode extension: GitHub - toradex/vscode-torizon-templates: VS Code Torizon Integrated Development Environment Templates

These are meant to be used with our extension: Visual Studio Code IDE Extension | Toradex Developer Center

But, they can be used as a reference as well. Some of the templates here use GTK.

Best Regards,
Jeremias

HI @Sudharshan,

I believe you need to set GDK_BACKEND=wayland before running gtk application. Can you check with same and see if this works for gtk application.

Best regards
Ritesh Kumar

Hi @ritesh.tx ,
Tried running it this way, weston compositor is already up , running the application container.
docker run --rm -it -e GDK_BACKEND=wayland -e DISPLAY=:0 mydockerimage:latest
Please correct me if I’m setting it up in wrong way.
Still got the same gtk display issue.

I tried out the Avalonia.net template in VS code which uses GTK

RUN apt-get -y update && apt-get install -y --no-install-recommends \
    # ADD YOUR PACKAGES HERE
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    # __torizon_packages_dev_start__
    # __torizon_packages_dev_end__
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
    libice6 \
    libsm6 \
    libicu72 \
    curl \
    gettext \
    apt-transport-https \
    libx11-6 \
	libunwind-13 \
    icu-devtools \
	libfontconfig1 \
	libgtk-3-0 \
    libgtk-3-bin \
    libgtk-3-common \
	libdrm2 \
	libinput10 \
    libssl3 \
	&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

the sample Avalonia application runs in one go.

So, two things here,

  1. You suggested to have separate containers for weston and my GTK application, but here with the template I can see the Avalonia application running on single container,
torizon@verdin-imx8mp-14753765:~$ docker ps
CONTAINER ID   IMAGE                          COMMAND               CREATED              STATUS              PORTS     NAMES
3ac5bb953616   172.17.54.146:5002/gtk:arm64   "/usr/sbin/sshd -D"   About a minute ago   Up About a minute             torizon-gtk-debug-1

how does that work? I see both weston and avolonia has different entry script. I would still prefer to have a single container running(if possible).

  1. On that very same running container, I installed my application libraries, put the application binary and ran my application, again got the same error.
15:51:08: Error: Unable to initialize GTK+, is DISPLAY set properly?

FYI, I’ve built my application with wxWidgets.

Regards,
Samarth

You suggested to have separate containers for weston and my GTK application, but here with the template I can see the Avalonia application running on single container,

Which avalonia template are you using? There’s 2 in the repository. One definitely needs weston as a supplementary container. The other runs directly on the framebuffer which is why it doesn’t need weston. But not all graphics frameworks can be easily ran on the framebuffer so this isn’t generally applicable.

On that very same running container, I installed my application libraries, put the application binary and ran my application, again got the same error.

Again are you running on the avalonia template that requires weston or the framebuffer one? If you’re running on the framebuffer one then maybe your application can’t run on framebuffer and requires weston/wayland.

FYI, I’ve built my application with wxWidgets.

We have not done have much testing with wxWidgets on our systems. It’s hard to say what the issue is here.

Best Regards,
Jeremias

Hi,
I’ve used the one using FB can confirm based upon the docker compose file, should have used the GTK one. The idea was to use the template and modify the Dockerfile, and run my app in multi container environment. Will check the one with weston, and let you know. Thanks.

Regards
Samarth

@jeremias.tx
Was able to get my app working with the avonia GTK container, which uses common/torizon-imx8 for display.

Thanks & regards.

Glad we were able to help get you started!