Display Android Studio GUI from Docker container while SSH tunneling through headless Ubuntu server
I was able to figure this out -- hopefully it helps someone else:
Step 1: Enable X11 forwarding on the server that hosting the Docker container
Make sure
/etc/ssh/sshd_config
contains the following line:X11Forwarding yes
SIGHUP
sshd
to pick up the changecat /var/run/sshd.pid | xargs kill -1
Verify
xauth
if installed on the serverwhich xauth
If it's not, then use your package manager to install it.
Step 2: SSH into the server hosting the Docker container
From Linux, your
ssh
command needs to include the-X
option. Example:ssh -X user@<IP_OF_DOCKER_SERVER>
From Windows (via PuTTY):
- Windows needs an X server installed; install XMing and ensure it's running.
- In PuTTY, go to 'Connection' > 'SSH' > 'X11' and check the box next to 'Enable X11 Forwarding', then connect to the server
Step 3: Run the docker run
command from the SSH'd terminal
docker run -it --rm --net=host -v "$HOME/.Xauthority:/root/.Xauthority:rw" -e DISPLAY="$DISPLAY" android-studio
Note: xorg-server
does not need to be installed on the Docker container.