Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote Containers on WSL shadows DISPLAY variable when invoking docker-compose #5043

Closed
i-ky opened this issue May 12, 2021 · 1 comment
Closed

Comments

@i-ky
Copy link

i-ky commented May 12, 2021

Somewhat related to #550 and #3841.

I have a project that uses zenity in auxiliary scripts to interact with developer. For it to work in Docker Compose environment I forward DISPLAY environment variable and tell service to use host network stack. This works fine on Linux (both using docker-compose CLI directly and using VS Code with Remote Containers) and it works in WSL with GWSL when containers are managed using docker-compose CLI, but it does not work in VS Code in WSL. The root cause seems to be that Remote Containers in WSL shadows DISPLAY variable with DISPLAY='1' when invoking docker-compose:

[8424 ms] Start: Run: wsl -d Ubuntu-18.04 -e /bin/sh -c cd '/tmp/display' && ... DISPLAY='1' ... docker-compose '--project-name' 'display' '-f' '/tmp/display/docker-compose.yml' 'up' '-d'
Recreating display_main_1 ... done
  • VSCode Version: 1.56.1
  • Remote Containers: 0.177.2
  • Local OS Version: WSL Ubuntu 18.04
  • Remote OS Version: official Ubuntu 18.04 Docker image
  • Remote Extension/Connection Type: Docker (on WSL)

Minimal project to reproduce:

  • .devcontainer/devcontainer.json:
{
    "dockerComposeFile": "../docker-compose.yml",
    "service": "main",
    "workspaceFolder": "/code"
}
  • docker-compose.yml:
services:
  main:
    init: true
    command: sleep infinity
    build:
      context: ./
    environment:
      DISPLAY:
    network_mode: host
    volumes:
    - ./:/code
  • Dockerfile:
FROM ubuntu:bionic

RUN apt-get update && apt-get --assume-yes --no-install-recommends install \
        zenity \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/*

WORKDIR /code

Steps to reproduce:

  1. Open folder in WSL.
  2. Click "Reopen in container" when prompted (assuming Remote Containers is installed).
  3. Open integrated terminal and run
$ echo $DISPLAY
  1. Observe result:
1
  1. Run on WSL:
$ docker-compose exec main zenity --info --text "Hello, world!"
  1. Observe failure:
Unable to init server: Could not connect: Connection refused

(zenity:328): Gtk-WARNING **: 13:10:43.286: cannot open display: 1

If you have GWSL integrated with WSL distro, DISPLAY should be set to <ip>:<port> and zenity should successfully display a window with text. However, the issue isn't necessarily specific to X forwarding, any other value of DISPLAY will be shadowed as well. It just happens that this particular variable name is very important for X forwarding and cannot be changed or worked around.

@i-ky
Copy link
Author

i-ky commented May 12, 2021

Sorry, the issue turned out to be that DISPLAY was missing from WSLENV.

@i-ky i-ky closed this as completed May 12, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant