2

I've been trying to get the following to work without success:

Dockerfile

FROM ubuntu:latest

#To install without any interactive dialogue
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update
# Installing Nautilus File Manager
RUN apt-get install nautilus -y

CMD ["nautilus"]

Then running with:

sudo docker build -t nautilus-ubuntu .

sudo docker run -it --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix nautilus-ubuntu

The error that I am getting is:

Unable to init server: Could not connect: Connection refused

This seems to have been asked heavily before but I've been trying for an hour all I could come across and there's nothing other than xhost + (which is insecure and I don't want to use) that can make this work.

One thing to note is that I am trying to get this to work in a way that I can build it and launch the target GUI app immediately, without having to log in to a bash session and do further things.

mangotango
  • 326
  • 4
  • 15
  • Try with entrypoint instead of cmd. Crate a sh file and copy to image, and the entrypoint have to execute it. In you sh file just write nautilus. I think it might work – S. Wasta Feb 23 '22 at 23:33
  • The only significant difference between `ENTRYPOINT` and `CMD` here is that `ENTRYPOINT` is harder to override if you need to debug the image. From the error message I gather the binary exists in the container and starts, it just can't connect to the X server; also see [Can you run GUI applications in a Linux Docker container?](https://stackoverflow.com/questions/16296753/can-you-run-gui-applications-in-a-linux-docker-container) – David Maze Feb 23 '22 at 23:43

1 Answers1

0

I found the answer here.

These should be added to the Dockerfile:

# Arguments picked from the command line!
ARG user
ARG uid
ARG gid

#Add new user with our credentials
ENV USERNAME ${user}
RUN useradd -m $USERNAME && \
        echo "$USERNAME:$USERNAME" | chpasswd && \
        usermod --shell /bin/bash $USERNAME && \
        usermod  --uid ${uid} $USERNAME && \
        groupmod --gid ${gid} $USERNAME

USER ${user}

WORKDIR /home/${user}

Then, creating xauth file:

xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f /tmp/.docker.xauth nmerge -

Then, running using:

docker build --build-arg user=$USER --build-arg uid=$(id -u) --build-arg gid=$(id -g) -t nautilus-ubuntu .

docker run -e DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v /tmp/.docker.xauth:/tmp/.docker.xauth:rw -e XAUTHORITY=/tmp/.docker.xauth -t nautilus-ubuntu
mangotango
  • 326
  • 4
  • 15