Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running GUI in docker (no ssh, no VNC)

TL;DR: root is not supposed to run GUI app, set a regular user to do so.

I'm trying to run arduino IDE (downloaded, not the package) from within a Docker. I wrote the Dockerfile as follow:

FROM ubuntu:14.04
MAINTAINER Mael Auzias <[email protected]>

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"]

I spent time to understand how does Jessica Frazelle usually starts her graphical containers to rightly start mine 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.

PS: as specified in the title I do not want to use ssh or VNC. No cryptography should be used nor network when a unix socket is faster and enough.


Solution

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 :/


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 <[email protected]>

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"]
like image 745
Auzias Avatar asked Sep 27 '22 01:09

Auzias


1 Answers

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 :/


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 <[email protected]>

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"]
like image 70
Auzias Avatar answered Oct 04 '22 02:10

Auzias