xfce inside docker container

Xfce inside Docker! Virtual Display Screen Inside Your Headless Container!

Want to have a virtual display running inside docker? You will need xvfb which is an ‘X virtual frame-buffer’ display server.

The following Dockerfile code installs xfce4 in a virtual screen.

ARG DEBIAN_FRONTEND=noninteractive
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get install keyboard-configuration -y
RUN apt install xfce4 xfce4-goodies -y
RUN apt install xvfb -y


ADD . .
RUN chmod a+x display.sh

CMD { bash display.sh; }

Because you still need a tty when running the docker file, run the Xfvb in a shell file at runtime. Here we are using DISPLAY number 99 for arbitrary reason.

docker run -t image

export DISPLAY=:99
Xvfb :99 -screen 0 1000x1000x16 &
xrandr --query
sleep 5
nohup startxfce4 &

Use xdotool to click the panel button (Add to script after startxfce4 has ran)

apt install xdotool -y
xdotool mousemove 493 539 click 1

Use xdotool to press enter

xdotool key KP_Enter

Verify the screen is “on” using

xrandr --query

Or take a screenshot using scrot

One thought on “Xfce inside Docker! Virtual Display Screen Inside Your Headless Container!”

Leave a Reply

Your email address will not be published. Required fields are marked *