0

I have been trying to run a GUI application inside a docker container and have spent a lot of time getting it to work but it's not working. This is how I try to run the docker container:

sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY myfirstdocker

I have also tried this way and many other ways:

sudo docker run -it myfirstdoocker

But I get this error message:

qt.qpa.screen: QXcbConnection: Could not connect to display unix:0
enter code here

The application is written in python and I'm installing both pyqt5, xvfb and all other dependencies you see below. I've tried setting the DISPLAY to 0, using ENV QT_QPA_PLATFORM offscreen, running the docker container with different commands but still I get the above error message. I have both my app scripts and the dockerfile in the same folder and have ubuntu operating system.

FROM ubuntu:18.04

RUN apt-get update

RUN apt-get update && apt-get install \
  -y --no-install-recommends python3 python3-virtualenv

COPY . .
ADD . .

RUN apt-get install -y python3-pip
RUN pip3 install --upgrade pip
RUN pip install --pre scapy[complete]
RUN pip install yapf
RUN apt-get install -y python3-pyqt5  
RUN apt-get install -y xvfb
RUN apt-get install -y qtbase5-dev
RUN apt-get install -y python-setuptools 

RUN apt-get install -y --no-install-recommends \
        libegl1-mesa \
        libgl1-mesa-dri \
        x11-xserver-utils \
        libxkbcommon-x11-0 \
        x11-utils \
        libnss3 \
        libasound2 \
    libxcb-xinerama0 \
    xserver-common

RUN apt-get install -y --no-install-recommends \
        libgstreamer1.0-0 \
        gstreamer1.0-plugins-base \
        gstreamer1.0-plugins-good \
        gstreamer1.0-plugins-bad \
        gstreamer1.0-plugins-ugly \
        gstreamer1.0-libav \
        gstreamer1.0-doc \
        gstreamer1.0-tools \
        libpulse-mainloop-glib0 \
        alsa-base \
        alsa-utils \
        pulseaudio

 ENV DISPLAY=:0
 ENV SCREEN=0
 ENV DBUS_SESSION_BUS_ADDRESS=/dev/null
 ENV XDG_RUNTIME_DIR=/run/user/1000

 RUN mkdir -p -m 0700 $XDG_RUNTIME_DIR && chown -R $USERNAME:users $XDG_RUNTIME_DIR

ENV QT_DEBUG_PLUGINS=0
ENV QT_VERBOSE true
ENV QT_TESTING true

CMD [ "python3", "./my_app.py" ]

Any help would greatly be appreciated.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Kevin T
  • 1
  • 1
  • what is your OS, try execute `xhost +` before `sudo docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY myfirstdocker ` – eyllanesc Aug 11 '20 at 19:40
  • Thank you for your reply. I’ve tried this as well but it didn’t work. My OS is Ubuntu 18.04 – Kevin T Aug 12 '20 at 04:09

0 Answers0