sebastiandaschner blog


Running Java Web Start Apps in a Docker sandbox

#java #docker sunday, july 19, 2015

There a various reasons why Java Web Start Apps aren’t really used anymore — mostly security based. But nevertheless sometimes you may need to run legacy application only available as JNLP file. These application can be run within a Docker container — even with GUI!

Therefore your Docker host has to have a graphical environment. If you aren’t working on Linux, this means your VM running your Docker containers needs a GUI.

This example shows how to connect your Docker container to an existing Linux X Server.

# from your favorite base image which includes the latest Java, this example uses Debian
FROM <your-java-base-image>

# xorg and sudo is needed to run X as non-root
RUN apt-get update && \
    apt-get install -y xorg sudo

# run X as non-root
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/dockeruser && \
    echo "dockeruser:x:${uid}:${gid}:Developer,,,:/home/dockeruser:/bin/bash" >> /etc/passwd && \
    echo "dockeruser:x:${uid}:" >> /etc/group && \
    echo "dockeruser ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/dockeruser && \
    chmod 0440 /etc/sudoers.d/dockeruser && \
    chown ${uid}:${gid} -R /home/dockeruser

USER dockeruser
ENV HOME /home/dockeruser

To run your container you connect the X Server Unix Socket to the Docker container.

# needed to allow local X clients
xhost +local:
docker run -ti --rm -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix/:/tmp/.X11-unix/ \
    -v /<directory-containing-jnlp-file>:/jnlp \
    <your-container> /bin/bash
dockeruser@62ed23a5ecf8:/$ javaws jnlp/dynamictree_webstart.jnlp

After the security question your Java Web Start Application will run in the Docker container:

docker jnlp example

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: