SDL2 Application Support

How do we run SDL2 based GUI Application in docker container. I am using Torizon OS running on Apalis i.MX8 Ixora Carrier board.

1 Like

Hi, I’m the Toradex AI Assistant.

I might make mistakes. Our support team will step in if needed. If I answered your question, please tick the “Solution” checkbox. For follow-up questions to me, please use @ToradexAI in your post.

Did you like my answer? :+1: :-1:


Hello! To run an SDL2-based GUI application in a Docker container on Torizon OS with an Apalis i.MX8 board, you should set up your environment to use a Wayland compositor. The recommended approach on Torizon OS is to use the Weston’s Vivante backend, which is provided via the official torizon/weston-vivante container.

Here’s a general approach to run your SDL2 application in a Docker container:

  1. Start the Weston Container

    Launch the Weston compositor in one terminal. You can do so with:

    docker run -d --rm \
      --name=weston \
      -v /tmp:/tmp \
      -v /run/udev/:/run/udev/ \
      -e ACCEPT_FSL_EULA=1 \
      --device=/dev/dri \
      --device=/dev/input \
      --security-opt seccomp=unconfined \
      torizon/arm64v8-debian-weston-vivante
    
  2. Prepare Your SDL2 Application Container

    Create a Dockerfile for your SDL2 application. Ensure it installs SDL2 and sets the environment variables for Wayland:

    FROM debian:bullseye
    
    RUN apt-get update && apt-get install -y \
      libsdl2-2.0-0 \
      libsdl2-image-2.0-0 \
      # add any other dependencies your app needs
      && rm -rf /var/lib/apt/lists/*
    
    WORKDIR /app
    COPY your-sdl2-app /app
    
    ENV DISPLAY=:0
    ENV WAYLAND_DISPLAY=wayland-0
    
    CMD ["./your-sdl2-app"]
    
  3. Run Your GUI Application Container

    Launch your application container so it can connect to the Wayland compositor:

    docker run --rm \
      -v /tmp:/tmp \
      -e WAYLAND_DISPLAY=wayland-0 \
      --device=/dev/dri \
      your-sdl2-image
    
    • The -v /tmp:/tmp part allows your application to access the Wayland display socket.
    • Ensure your SDL2 application is built with Wayland support.
  4. Additional Tips

    • If you want to manage multiple containers and their dependencies, consider using Docker Compose.
    • You can refer to detailed steps for setting up GUI applications in containers here: Preparing the Environment.

If you’re interested in trying other GUI frameworks with better-documented support, see:

Please let me know if you need specifics for creating the Dockerfile or assistance with application deployment.

Best regards,
Toradex AI Assistant.

Hi @kushal.dalsania!

The Toradex AI answer seems to give a good starting point. Were you able to test it?

Best regards.