el n00b
el n00b

Reputation: 1863

Docker with GUI application

TL;DR

I need to kick off Selenium from a Java application running in the background in a Docker container. The kick off fails because the X11 environment is not accessible during runtime. See Dockerfile below that I am starting with.

What should I do?

Problem

I am starting with a simple Dockerfile that installs Java 8 and Jetty 9.3.x to run a simple service (Selenium stuff, actually). The service is actually set up to kick off some things that require a UI in order to execute. The problem I am having is that the execution of anything in there fails because the UI is not available in the configuration I have running. I have some other things running with supervisord, but this is the basic setup:

Dockerfile

FROM ubuntu:16.04

RUN apt-get update -y && \
    apt-get install -y software-properties-common wget supervisor && \
    mkdir -p /var/log/supervisor && \
    mkdir -p /etc/supervisor/conf.d

RUN useradd -Ums /bin/bash jetty

RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
  add-apt-repository -y ppa:webupd8team/java && \
  apt-get update && \
  apt-get install -y oracle-java8-installer && \
  rm -rf /var/lib/apt/lists/* && \
  rm -rf /var/cache/oracle-jdk8-installer

ENV JAVA_HOME /usr/lib/jvm/java-8-oracle

ENV JETTY_VERSION "9.3.7.v20160115"
ENV JETTY_HOME "/opt/jetty"

RUN wget -q -O /opt/jetty.tgz "http://download.eclipse.org/jetty/${JETTY_VERSION}/dist/jetty-distribution-${JETTY_VERSION}.tar.gz" && \
    cd /opt && \
    tar -zxvf /opt/jetty.tgz && \
    rm /opt/jetty.tgz && \
    mv "/opt/jetty-distribution-${JETTY_VERSION}" "${JETTY_HOME}" && \
    chown -R jetty:jetty "${JETTY_HOME}"

ADD supervisor.conf /etc/supervisor.conf
ADD jetty.sv.conf /etc/supervisor/conf.d/jetty.sv.conf

CMD ["supervisord", "-c", "/etc/supervisor.conf"]

jetty.sv.conf

[program:jetty]
command=/usr/bin/java -jar /opt/jetty/start.jar jetty.home=/opt/jetty jetty.base=/opt/jetty
redirec_stderr=true
startsecs=5

I want to ensure that everything runs in a UI environment rather than in the headless environment.

What I Tried

I tried using the VNC and shared desktop setup as in these:

However, this still doesn't allow my Java application to execute GUI applications. As usual, I'm sure I'm missing something simple here.

How can I execute the Jetty container with access to the UI?

Upvotes: 2

Views: 3456

Answers (2)

user9088901
user9088901

Reputation: 1

We can also connect a docker container directly to a users Xserver: See the answer to Can you run GUI apps in a docker container?

Upvotes: -2

Evedel
Evedel

Reputation: 705

We have almost the same case. Bamboo is CI/CD tool, selenium and java8 is tool for regression tests, and all these are running inside of a docker container. So I can say that it is 100% possible.

What probably can help you is xvbf (headless X-server) and x11vnc (vnc-server to see what actually happening inside of container)

RUN set -x &&\
    apt-get update &&\
    apt-get install -y xvfb x11vnc &&\
    apt-get clean autoremove &&\
    mkdir ~/.vnc/ && x11vnc -storepasswd 111222 ~/.vnc/passwd &&\
    echo "export DISPLAY=:0" >> ~/.bashrc

If you want, you can also install firefox

RUN     set -x\
        && curl -O https://ftp.mozilla.org/pub/firefox/releases/47.0.1/linux-x86_64/ru/firefox-47.0.1.tar.bz2\
        && tar xvjf firefox-47.0.1.tar.bz2 -C /usr/local/src\
        && rm -rf firefox-47.0.1.tar.bz2\
    && ln -s /usr/local/src/firefox/firefox /usr/local/bin/firefox

Also add this command to startup wizard or entrypoint script

source ~/perl5/perlbrew/etc/bashrc
rm -f /tmp/.X10-lock
Xvfb :0 -screen 0 1600x1200x24 &
firefox -height 1200 -width 1600 &
x11vnc -usepw -forever -shared &

As result after you start container, you will be able to connet to this container through any vnc client and see firefox welcome page, or how webtests go, in case they are running.

Upvotes: 2

Related Questions