SSH X11 & docker post
Purpose
Run GUI application inside a docker container using X11Forwarding.
Create a container
DockerFile
FROM ubuntu
RUN apt update \
&& apt install -y firefox \
openssh-server \
xauth \
emacs \
&& mkdir /var/run/sshd \
&& mkdir /root/.ssh \
&& chmod 700 /root/.ssh \
&& ssh-keygen -A \
&& sed -i "s/^.*PasswordAuthentication.*$/PasswordAuthentication no/" /etc/ssh/sshd_config \
&& sed -i "s/^.*X11Forwarding.*$/X11Forwarding yes/" /etc/ssh/sshd_config \
&& sed -i "s/^.*X11UseLocalhost.*$/X11UseLocalhost no/" /etc/ssh/sshd_config \
&& grep "^X11UseLocalhost" /etc/ssh/sshd_config || echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
RUN echo "CONTENT_OF_ID_RSA_PUB_KEY_HERE" >> /root/.ssh/authorized_keys
Build it
docker build -t benit/ubuntu-x11 . --build-arg http_proxy=$http_proxy
Run Container
docker run --name ubuntu-x11 --rm -d -p 2150:22 benit/ubuntu-x11
SSH client configuration
Edit ~/.ssh/config
on the client, here my workstation is named lxdev
:
Host ubuntuX11
Hostname lxdev
Port 2150
user root
ForwardX11 yes
ForwardX11Trusted yes
Use it!
ssh -X ubuntu-x11 emacs