Docker Community Forums

Share and learn in the Docker community.

Running GUI in docker


(Auzias) #1

Hi everyone.

I’m trying to run arduino IDE from within a Docker. I wrote the Dockerfile as follow:

FROM ubuntu:14.04
MAINTAINER Mael Auzias <docker@mael.auzias.net>

ENV HOME /home/arduino
ENV USER arduino

RUN apt-get update && apt-get install -y \
   libx11-6 libxext-dev libxrender-dev libxtst-dev \
    --no-install-recommends \
    && useradd --create-home --home-dir $HOME $USER \
    && chown -R $USER:$USER $HOME

ADD arduino-1.6.6-linux64.tar.xz $HOME

WORKDIR $HOME/arduino-1.6.6
USER $USER

ENTRYPOINT ["/bin/bash"]

and start the container with the command:

$docker run --name arduino --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix 25af73b6cb3c ./arduino
No protocol specified
Picked up JAVA_TOOL_OPTIONS: 
No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.

I installed strace and check with xeyes what was wrong, and I get the following error:

connect(3, {sa_family=AF_LOCAL, sun_path=@"/tmp/.X11-unix/X0"}, 20) = -1 ECONNREFUSED (Connection refused)

Did anyone experience this? Can any point me out some doc or see what I’m doing wrong?

Any help would be welcome :slight_smile:


(Auzias) #2

Got some news…

As the user root I cannot start graphical application. When I su regular-user and start xterm or xeyes it works. I don’t really understand why though :confused:


Here is the working Dockerfile, tested on Fedora 23.
The application must not be ran as root so it starts using X.
Note that, unrelated to this issue, a Java option has been removed from the bash file arduino (so it starts properly).

After a docker build -t arduino-1.6.6 ., docker run --name arduino --rm -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix arduino-1.6.6 ./arduino start the arduino IDE.

You will not be able to upload any code into an arduino without adding a --device or -v to share the /dev/ttyUSB0.

FROM ubuntu:14.04
MAINTAINER Mael Auzias <docker@mael.auzias.net>

ENV HOME /home/arduino
ENV USER arduino

RUN apt-get update && apt-get install -y \
        libx11-6 libxext-dev libxrender-dev libxtst-dev \
        --no-install-recommends \
        && rm -rf /var/lib/apt/lists/* \
        && useradd --create-home --home-dir $HOME $USER \
        && chown -R $USER:$USER $HOME

ADD arduino-1.6.6-linux64.tar.xz $HOME
RUN sed -i 's/"-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel"//g' /home/arduino/arduino-1.6.6/arduino

WORKDIR $HOME/arduino-1.6.6
USER $USER

ENTRYPOINT ["/bin/bash"]