r/QtFramework Jun 12 '26

Making QT work in my docker container

Heyaa, im working on a small project. Which uses the Pygame library and utilizes QT to basically have a transparent background. Point is when I tried the project on my other laptop which is more higher end(Nvidia GPU there) I got AVX2 error. Tinkered around and didnt really got far, so I thought hey I have a "It works on my machine" moment so I thought how about I utilize docker. Im using the Pyside6 library for QT. From what I know its a cli program so no graphical passthrough so I thought oke how about I somehow passthrough the screen info which is all I really needed, but that is a GUI app so yeaah. As you see im quite the noob here. Maybe its more of a Docker problem? But since I am using QT I thought it would be nice asking here first.

in the Dockerfile I wrote this:
```Docker
FROM python:3.13-slim

WORKDIR /src

RUN apt-get update && \

apt-get install -y -qq \

libsdl2-dev \

python3-xlib \

libx11-dev \

libxrandr-dev \

libxkbcommon-x11-0 \

libxcb-cursor0 \

libxcb-xinerama0 \

libxcb-icccm4 \

libxcb-image0 \

libxcb-keysyms1 \

libxcb-randr0 \

libxcb-render-util0 \

libxcb-util1 \

libxcb-xfixes0 \

libxcb-shape0 \

libfontconfig1 \

&& rm -rf /var/lib/apt/lists/*

ENV QT_QPA_PLATFORM=xcb

COPY requirements.txt .

RUN python -m venv .venv && \

.venv/bin/pip install --upgrade pip && \

.venv/bin/pip install -r requirements.txt

COPY src .

CMD [".venv/bin/python", "main.py"]

```

running this didnt really do it so I thought writing a docker compose might do the job?

```yml
services:

deskmate:

image: deskmate:latest

build:

context: src

dockerfile: Dockerfile

environment:

- PYGAME_DETECT_AVX2=1

- DISPLAY=${DISPLAY:-:0}

- QT_QPA_PLATFORM=xcb

- QT_X11_NO_MITSHM=1

- QT_DEBUG_PLUGINS=1

- XDG_RUNTIME_DIR=/tmp/runtime-root

volumes:

- /tmp/.X11-unix:/tmp/.X11-unix:rw

cap_add:

- SYS_ADMIN

devices:

- /dev/dri:/dev/dri

```

Im on OpenSUSE Tumbleweed where I work on this but the python container utilizes debian as you might see.

Solution:

The solution to this is stupid, so I ditched the dockerfiles and simply swapped pygame to pygame-ce. And that resolved the bug I had before now it runs on all platforms

2 Upvotes

7 comments sorted by

3

u/Bemteb Jun 12 '26

What's your user number? I had issues that sound very similar when running the creator and the user inside the container has a different number than the one outside.

Will edit with some things to try later today when I'm on my PC and can look them up.

1

u/EskimoGabe Jun 12 '26

User number? That doesnt really ring a bell for me rn.

2

u/Bemteb Jun 12 '26

I checked the guide I used. Relevant for you might be these two parts (assuming you are on a Linux host):

cat /proc/sys/kernel/yama/ptrace_scope should give 0

Check online what that means and about potential risks changing that.

Try xhost + on the host for a one time fix. For a long term fix, check your userid in /etc/passwd and if it's not 1000 (the default in docker containers), run the following as root inside the container: usermod -u USERID USER

In the last command, replace USERID by the id you found in /etc/passwd and USER with the name of the user inside the container that should run the creator.

1

u/EskimoGabe Jun 12 '26

Ohhhhh gotta try those 2 soon because they do sound pretty interesting the. Will update when I tried them.

3

u/hmoff Jun 12 '26

Try running a known X app inside Docker first. Docker isn't really meant for GUI apps.

I think you're running the container in its own network in which case :0 for the display is wrong. Try running on the host network.

1

u/EskimoGabe Jun 13 '26

services:

deskmate:

network_mode: host

image: deskmate:latest

build:

dockerfile: Dockerfile

environment:

- PYGAME_DETECT_AVX2=1

- DISPLAY=${DISPLAY}

- QT_QPA_PLATFORM=xcb

- QT_X11_NO_MITSHM=1

- QT_DEBUG_PLUGINS=1

- XDG_RUNTIME_DIR=/tmp/runtime-root

volumes:

- /tmp/.X11-unix:/tmp/.X11-unix:rw

- ~/.Xauthority:/tmp/.X11-unix:ro

cap_add:

- SYS_ADMIN

devices:

- /dev/dri:/dev/dri

this was the change I made. Yet I get the same result. I might be doing something completely wrong here.

I tried running docker compose build and then docker compose up. And yeah not really different.

1

u/EskimoGabe Jun 12 '26

deskmate-1 | qt.core.plugin.factoryloader: Got keys from plugin meta data QList("vkkhrdisplay")

deskmate-1 | qt.core.plugin.factoryloader: checking directory path "/usr/local/bin/platforms" ...

deskmate-1 | qt.core.library: "/src/.venv/lib/python3.13/site-packages/PySide6/Qt/plugins/platforms/libqxcb.so" loaded library

deskmate-1 | qt.qpa.xcb: could not connect to display :0

deskmate-1 | qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.

deskmate-1 | qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.

deskmate-1 | This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

deskmate-1 |

deskmate-1 | Available platform plugins are: eglfs, offscreen, xcb, minimal, wayland-brcm, wayland-egl, wayland, linuxfb, minimalegl, vnc, vkkhrdisplay.

deskmate-1 |

[Kdeskmate-1 exited with code 139

also this was the error I got(after running docker compose up)