Display Android Studio GUI from Docker container while SSH tunneling through headless Ubuntu server Display Android Studio GUI from Docker container while SSH tunneling through headless Ubuntu server docker docker

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

  1. Make sure /etc/ssh/sshd_config contains the following line:

    X11Forwarding yes
  2. SIGHUP sshd to pick up the change

    cat /var/run/sshd.pid | xargs kill -1
  3. Verify xauth if installed on the server

    which 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.