cli icon indicating copy to clipboard operation
cli copied to clipboard

X11 works with container launched via VSCode but not launched via devcontainers/cli

Open jbcpollak opened this issue 1 year ago • 3 comments

I have a script called devshell (relevant code below), which is intended to start the devcontainer if not always running, then give you a shell into the container.

When I start the container in VSCode, then in a separate terminal (outside vscode) run devshell, I can launch a GUI application like xterm no problem.

If instead, I stop VSCode and the running devcontainer, then run the devshell script below, xterm and other X11 applications do not work. It seems to me devcontainer up does something different than vscode itself when preparing the container for execution.

Here is the relevant except of devshell (the only missing contents are boilerplate setup and making sure we are in the right directory, etc):

devcontainer up --workspace-folder .

WORKDIR=/workspaces/${REPONAME}
CONTAINER_NAME=${REPONAME}_devcontainer

# Run a shell in the container
docker exec -it -e DISPLAY=":0" -w ${WORKDIR} ${CONTAINER_NAME} /bin/bash "$@"

jbcpollak avatar Aug 05 '24 18:08 jbcpollak

The X11 forwarding is a feature of the Dev Containers extension for VS Code and not part of the Dev Containers CLI.

chrmarti avatar Sep 03 '24 12:09 chrmarti

Oh that's disappointing. Is there any way to bring it over?

jbcpollak avatar Sep 03 '24 15:09 jbcpollak

I cannot get VSCode-launched devcontainers to work with QT apps, though xterm does start.

However there is an easy workaround that should also help you:

    "containerEnv": {
        "DISPLAY": "${localEnv:DISPLAY}",
	"XAUTHORITY": "${localEnv:XAUTHORITY}",
    },
    "mounts": [
	"source=${localEnv:XAUTHORITY},target=${localEnv:XAUTHORITY},type=bind",
        "source=/tmp/.X11-unix,target=/tmp/.X11-unix,type=bind",
	"source=/dev/dri,target=/dev/dri,type=bind",
    ],

akvadrako avatar May 13 '25 16:05 akvadrako