How do we run SDL2 based GUI Application in docker container. I am using Torizon OS running on Apalis i.MX8 Ixora Carrier board.
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.
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:
-
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
-
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"]
-
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.
- The
-
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.
Would be great if you can suggest the changes needs to be done in VSCode project to start developing SDL2 Application
Hi @kushal.dalsania!
Since the community is focused on Toradex hardware and/or software, we don’t have the necessary expertise to configure or set up VSCode to work with SDL2. I recommend taking a look at the SDL2 wiki, where you can probably find useful information.
Besides that, we have our Partner Network, where you can find capable partners to help you accelerate the project and develop the application.
Best regards.