Devcontainer for developing an application with a GUI

Hi,

I just landed to Bluefin from Ubuntu after one year reading good things about it. So far I’m very happy with the experience and I’m just working on things that are new concepts for me.

One of them are devcontainers. I read about them in the past but I never used them. To get acquaintance with the technology, I started to use devcontainers in one of my toy projects.

First, I thought that it would be simplier, but the deccontainer.json file keeps growing with new options and arguments. I’m at a point where I can run pytest both from the VS Code testing interface and the command line (via poetry run pytest.

However, if I try to start my main application it fails with an exception (see bellow) that makes me think of “you need to share the host’s display with the docker container”.

If, instead of devcontainers, I create an Ubuntu container with Distrobox, install poetry and later my program, it starts normally.

I’m looking for help to get this working in VS Code and Devcontainers, since I’d like to get it working. I can always keep developing in VS Code and run my program from Distrobox, but it does not look the best way to develop.

Cheers,
Manuel

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/workspaces/chip8emulator/chip8emulator/chip8emulator.py", line 117, in main
    window = Chip8Emulator(rom=rom_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/chip8emulator/chip8emulator/chip8emulator.py", line 31, in __init__
    super().__init__(width=width, height=height, title="Chip-8 Emulator")
  File "/workspaces/chip8emulator/.venv/lib/python3.12/site-packages/arcade/application.py", line 116, in __init__
    display = pyglet.canvas.get_display()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/chip8emulator/.venv/lib/python3.12/site-packages/pyglet/canvas/__init__.py", line 94, in get_display
    return Display()
           ^^^^^^^^^
  File "/workspaces/chip8emulator/.venv/lib/python3.12/site-packages/pyglet/canvas/xlib.py", line 123, in __init__
    raise NoSuchDisplayException('Cannot connect to "%s"' % name)
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"

Here is my devcontainer.json file

Maybe this helps? Display forwarding from docker container · Issue #550 · microsoft/vscode-remote-release · GitHub

You might need to run GNOME with Xorg (I think? Not sure) instead of Wayland for it to work.

Unfortunately it did not work. It is not Bluefin “pure Wayland”?

Just to make sure that it is not a problem with the Python libraries of my project, I setup a new project with QT. The result is the same (no GUI opening via devcontainers) with this output:

qt.qpa.plugin: Could not load the Qt platform plugin "wayland" in "" even though it was found.
qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

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

Aborted (core dumped)

I finally got it working:

	"runArgs": [
		"--device=/dev/dri",
		"--env=WAYLAND_DISPLAY=${localEnv:WAYLAND_DISPLAY}",
		"--network=host"
		// "--env=XDG_RUNTIME_DIR=${localEnv:XDG_RUNTIME_DIR}",
		// "--env=DBUS_SESSION_BUS_ADDRESS=unix:path=${localEnv:XDG_RUNTIME_DIR}/bus",

	],
	"mounts": [
		"source=${localEnv:XAUTHORITY},target=/home/vscode/.Xauthority,type=bind,consistency=cached",
		// "source=${localEnv:XDG_RUNTIME_DIR},target=${localEnv:XDG_RUNTIME_DIR},type=bind,consistency=cached",
		// "source=${localEnv:XDG_RUNTIME_DIR}/${localEnv:WAYLAND_DISPLAY},target=${localEnv:XDG_RUNTIME_DIR}/${localEnv:WAYLAND_DISPLAY},type=bind",
		// "source=${localEnv:XDG_RUNTIME_DIR}/bus,target=${localEnv:XDG_RUNTIME_DIR}/bus,type=bind"
	],

For me, it works commenting those mounts and arguments. But I leave it there in case it is useful for other use cases.

Now, some more context. My project uses a library called arcade, which uses pyglet. Pyglet does not support Wayland, what means that we need to mount (maybe bridge would be a better term) the X system in the container with the Wayland system in the host. The same applies for pygame.

I still get an error when I start my project:

amdgpu: unknown (family_id, chip_external_rev): (148, 10)
libGL error: failed to create dri screen
libGL error: failed to load driver: radeonsi

Which seems to be related to my GPU (Framework 13 AMD). So far, I can continue the development of my project and I will get back to those error in the future. But if someone has already some information about how to solve it, it will be very welcome :wink:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.