Mason
Mason

Reputation: 4735

Different behavior of Docker and Docker Compose when exposing X

I am trying to run X apps within a docker container and display the GUI.
I got this working with Docker Compose, but when running the same container from the command line with docker run, it fails.

I have created a minimal example to try to demonstrate what is happening:

Dockerfile:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y x11-apps
RUN useradd -ms /bin/bash xvis
USER xvis
WORKDIR /home/xvis

docker-compose.yml:

version: "3"
services:
  xeyes-test:
    build: .
    command: xeyes
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
    environment:
      DISPLAY: unix:0

docker-compose up --build brings up the xeyes GUI, as expected.

docker build -t xeyes-docker-test .
docker run --rm -e DISPLAY:unix:0 -v /tmp/.X11-unix:/tmp/.X11-unix xeyes-docker-test xeyes

gives the error: Error: Can't open display:

Upvotes: 0

Views: 351

Answers (1)

DazWilkin
DazWilkin

Reputation: 40081

The docker run command should be -e DISPLAY=unix:0 (= not :).

If that doesn't resolve it, see: https://github.com/jessfraz/dockerfiles/issues/329

Upvotes: 1

Related Questions