0

My intention is to run a GUI jar file in Docker so I could automate commands with xdotool and may view it by x11vnc.

This is my Dockerfile:

# WEB 0.1

FROM ubuntu:14.04
RUN apt-get update \
 && apt-get install -y \
  default-jre \
  x11vnc \
  xdotool \
  xsel \
  xvfb \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN DISPLAY=:1.0 \
 && export DISPLAY \
 && mkdir /root/.vnc \
 && x11vnc -storepasswd 1234 /root/.vnc/passwd \
 && Xvfb :1 -screen 0 493x476x8 & \
 x11vnc -display :1.0 -usepw -forever &

ENTRYPOINT ["java"]
CMD ["-jar", "/var/bin/program.jar"]

I run it with:

docker run \
  --name program-jar \
  -p 5090:5900 \
  -v /var/bin/program-jar/:/var/bin/ \
  -d program-jar:0.1

But inside this container it is not defined $DISPLAY and is not running x11vnc and Xvfb

root@62febbc0b8f9:/# echo $DISPLAY

root@62febbc0b8f9:/# ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1 11.7  0.9 4226956 98588 ?       Ssl  14:30   0:01 java -jar /var/bin/program.jar
root        26  0.2  0.0  18188  3268 ?        Ss   14:30   0:00 /bin/bash
root        41  0.0  0.0  15580  2044 ?        R+   14:30   0:00 ps aux
root@62febbc0b8f9:/# 

(If I run those commands in RUN inside bash it work... don't know why RUN seems not to work when run the docker build)

Paulo Henrique
  • 938
  • 1
  • 13
  • 19

2 Answers2

1

docker uses a layer file system when you RUN it create a separate layer for the installation it is NOT use to run a program but it is use to download source code or build from source code etc. for example RUN mvn package

The way you should do this is create a shell script commonly they call it bootstrap.sh you copy that into your container COPY bootstrap.sh /app or something like that you can then put in this command

#!/bin/bash

DISPLAY=:1.0 \
 && export DISPLAY \
 && mkdir /root/.vnc \
 && x11vnc -storepasswd 1234 /root/.vnc/passwd \
 && Xvfb :1 -screen 0 493x476x8 & \
 x11vnc -display :1.0 -usepw -forever &

java -jar /var/bin/program.jar

into your shell script and the last command in your dockerfile change it to CMD ./bootstrap.sh something like that

Hamuel
  • 633
  • 5
  • 16
  • So the process executed in one layer are not running into child layers? Only the filesystem is inherited? – Paulo Henrique Aug 23 '17 at 14:52
  • yep for the run command create another container (aka layer) that other container could use also for example the ubuntu 14 layer could be use by multiple containers however the last layer that get created is the one that get run for stay alive (if you docker run it in detach mode) – Hamuel Aug 23 '17 at 14:55
0

add to your docker run

command

-v $HOME/.Xauthority:/home/developer/.Xauthority -v /tmp/.X11-unix:/tmp/.X11-unix:ro

and if you need some EXPORT, the

ENV

directive

is designed for this, see

https://docs.docker.com/engine/reference/builder/#env

user2915097
  • 30,758
  • 6
  • 57
  • 59
  • It would execute the GUI always in my host, isn't it? That's not exactly what I want. I want to run the jar inside the container and visualize just if needed. That's why I installed x11vnc. – Paulo Henrique Aug 23 '17 at 15:06