Score:2

Open a GUI in a Docker container running on a headless machine

in flag

I'm trying to open Firefox GUI on a Docker container. I'm avoiding most common solution which seems to use at one point /tmp/.X11-unix from host because I want the container to work on any host, including a headless host without X11.

The goal is just to use selenium to open Firefox GUI and take a screenshot. I'm not quite sure if it possible but I guess it is.

FROM ubuntu:latest

RUN DEBIAN_FRONTEND="noninteractive" apt-get -y update
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install python3 python3-pip firefox-geckodriver x11vnc xvfb
RUN DEBIAN_FRONTEND="noninteractive" apt-get -y install x11-xserver-utils
RUN DEBIAN_FRONTEND="noninteractive" pip install --upgrade --no-cache-dir pip-with-requires-python && \
    pip install --upgrade --no-cache-dir --prefer-binary selenium

WORKDIR /app

COPY entrypoint.sh .
COPY script.py .

RUN chmod +x entrypoint.sh

CMD ["x11vnc", "-create", "-forever"]
ENV DISPLAY :0
CMD ["xhost", "+"]

ENTRYPOINT ["/app/entrypoint.sh"]

Currently xhost ouput xhost: unable to open display :0. I'm not sure about the :0 but I tried several values.

Selenium of course also fails with:

Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

I'm running out of ideas so anything would be appreciated :) I'm probably missing an important part.

muru avatar
us flag
You're not going to start a GUI that depends on X11 without X11 running *somewhere*. You could start Firefox itself in a headless mode and ask it to take the screenshot or whatever, e.g., https://stackoverflow.com/a/48377879/2072269
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.