13

The question is most clear,
How to start complete desktop environment (KDE, XFCE, Gnome doesn't matter) in the Docker remote container.

I were digging over the internet and there are lots of questions about the related topic, but not the same, they all about how to run GUI application not the full desktop.

What I found out:

  • Necessary run Xvfb
  • Somehow run e.g. Xfce in that FrameBuffer
  • Allow x11vnc to share that running X environment

But I'm stuck here actually, always getting whatever errors:

... (EE) Invalid screen configuration 1024x768 for -screen 0
... Cannot open /dev/tty0 (No such file or directory)

Could you give some Dockerfile lines in order reach the goal?

Ivan Talalaev
  • 6,014
  • 9
  • 40
  • 49

2 Answers2

11

That is I was looking for, the simplest form of the desktop in Docker:

FROM ubuntu
RUN apt-get update
RUN apt-get install xfce4 -y
RUN apt-get install xfce4-goodies -y
RUN apt-get purge -y pm-utils xscreensaver*
RUN apt-get install wget -y

EXPOSE 5901

RUN wget -qO- https://dl.bintray.com/tigervnc/stable/tigervnc-1.8.0.x86_64.tar.gz | tar xz --strip 1 -C /
RUN mkdir ~/.vnc
RUN echo "123456" | vncpasswd -f >> ~/.vnc/passwd
RUN chmod 600 ~/.vnc/passwd


CMD ["/usr/bin/vncserver", "-fg"]

Unfortunately I could not sort out with x11vnc and xvfb. But TigerVNC turned out much better.

This sample generate container with xfce gui and run vncserver with 123456 password. There is no need to overwrite ~/.vnc/xstartup manually because TigerVNC starts up X server by default!

To run the server:

sudo docker run --rm -dti -p 5901:5901 3ab3e0e7cb

To connect there with vncviewer:

vncviewer -AutoSelect 0 -QualityLevel 9 -CompressLevel 0 192.168.1.100:5901

Also you could not care about screen resolution because by default it will resize to fit your screen: F8 vncviewer menu

You may also encounter the issue with ipc_channel_posix (chrome and other browsers will not work properly) to eliminate this run container with memory sharing:

docker run -d --shm-size=2g --privileged -p 5901:5901 image-name
Ivan Talalaev
  • 6,014
  • 9
  • 40
  • 49
3

x11docker allows to run desktop environments as well as single GUI applications in docker.

Could you give some Dockerfile lines in order reach the goal?

Example desktop images on docker hub.

x11docker does a lot of setup to keep container isolation and provides some additional options like hardware acceleration or pulseaudio sound. Example:

x11docker --desktop x11docker/lxde

x11docker also supports network setups with SSH, VNC and HTML5

Example for SSH setup with xpra:

read Xenv < <(x11docker --xdummy --display=30 x11docker/lxde pcmanfm)
echo $Xenv && export $Xenv
# replace "start" with "start-desktop" to forward a desktop environment
xpra start :30 --use-display --start-via-proxy=no

From client system, connect with

xpra attach ssh:HOSTNAME:30  # replace HOSTNAME with IP or host name of ssh server

Without x11docker:

A quite short setup using Xephyr as nested X server on host is:

Xephyr :1
docker run -v /tmp/.X11-unix/X1:/tmp/.X11-unix/X1:rw \
           -e DISPLAY=:1 \
           x11docker/xfce

A short Dockerfile with Xfce desktop:

FROM debian:stretch
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends xfce4 dbus-x11
CMD startxfce4
mviereck
  • 1,309
  • 1
  • 12
  • 15
  • Great `x11docker` project! and many thanks for answer, but unfortunately I need **remote** vnc connection. – Ivan Talalaev Dec 24 '17 at 08:16
  • It is possible to set up a VNC connection with x11docker, I have edited the answer. Though, I am not experienced with VNC. Compare this diskussion: https://github.com/mviereck/dockerfile-x11docker-xfce-wine-playonlinux/issues/1 . An SSH setup with xpra works quite well and is more tested. – mviereck Dec 24 '17 at 12:32