XDummy in Docker container
Asked Answered
D

2

17

I am trying to run a X11 server inside a docker container by using the XDummy driver. However, I have problems getting it to work. The intended purpose is to perform headless rendering. I can get it to work using Xvfb, but I need RANDR support, and eventually going to need GL support as well.

Dockerfile:

FROM node:slim

RUN mkdir nodeapp \
    && apt-get update \
    && apt-get install -y xorg \
    && apt-get install -y xserver-xorg-video-dummy x11-apps

COPY App /nodeapp/

ENV DISPLAY :1

RUN cd nodeapp/ \
    && npm install \
    && Xorg -noreset +extension GLX +extension RANDR +extension RENDER -logfile /nodeapp/xdummy.log -config /nodeapp/xorg.conf start :1 &

ENTRYPOINT [ "node", "/nodeapp/index.js" ]

The xorg.conf file is the basic Xdummy xorg.conf

However, the xserver does not boot, and the logfile does not provide anything useful, but I am certain I am doing something wrong when setting up Xorg in the Dockerfile, but I can't find any examples doing anything similar.

What is the recommended procedure to make this work?

Danube answered 22/8, 2016 at 17:30 Comment(0)
B
13

I subscribe to the "one thing per container" Docker philosophy, so I modified your solution to only do XDummy. It can easily be linked to another container.

FROM debian:jessie

ENV DEBIAN_FRONTEND noninteractive
ENV DISPLAY :1

RUN apt-get update \
    && apt-get -y install xserver-xorg-video-dummy x11-apps

VOLUME /tmp/.X11-unix

COPY xorg.conf /etc/X11/xorg.conf

CMD ["/usr/bin/Xorg", "-noreset", "+extension", "GLX", "+extension", "RANDR", "+extension", "RENDER", "-logfile", "./xdummy.log", "-config", "/etc/X11/xorg.conf", ":1"]

And then to access, link the /tmp/.X11-unix volume and set DISPLAY=:1 in your environment.

Budwig answered 14/3, 2017 at 18:13 Comment(2)
your solution is quite neat. I had problems to problems to understand what you meant by "link the /tmp/.X11-unix volume". For anybody who is also interested here is what I did: docker volume create --name x11tmp and add -v x11tmp:/tmp/.X11-unix to both run commands for creating the containers.Stomatic
I left it kind of vague because linking is done differently whether you're using bare docker, docker compose, or kubernetes, and there are several ways of doing it with each. :) However, your suggestion is probably the best way for the most common mechanism, so thanks!Budwig
D
7

Managed to solve this, if anyone else is looking for a solution.

FROM node:slim

ENV DEBIAN_FRONTEND noninteractive
ENV DISPLAY :1

RUN mkdir nodeapp \
    && apt-get update \
    && apt-get -y install xserver-xorg-video-dummy x11-apps

COPY App /nodeapp/

RUN cd nodeapp/ \
    && npm install

ENTRYPOINT [ "node", "/nodeapp/index.js" ]

The problem was that apt-get was asking for keyboard config inside the docker container while installing, and that the dummy package provided all dependencies, so the regular xorg install was not needed.

The last issue was that I could not start Xorg and the nodeapp at the same time, but that was a easy fix. I already use node to manage services, so I moved the part starting Xorg into that.

var args = ["-noreset", "+extension", "GLX", "+extension", "RANDR", "+extension", "RENDER", "-logfile", "./xdummy.log", "-config", "/mplex-core/xorg.conf", ":1"];
this.proc = child_process.spawn("Xorg", args);
Danube answered 23/8, 2016 at 15:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.