-
Notifications
You must be signed in to change notification settings - Fork 416
Remote access with SSH
You can run x11docker on remote servers with ssh -X like a regular X application. Example:
# Replace localhost with address of your desired server
ssh -X localhost -- x11docker x11docker/lxde lxterminal
If your server has e.g. Xephyr or nxagent installed, you can run desktop environments like a VNC session:
ssh -X localhost -- x11docker --desktop x11docker/lxde
It is recommended to provide a nested X server like nxagent on the remote machine to allow x11docker circumventing X security leaks.
The image must contain xauthand an ssh server like openssh-server.
Start the container with options
--runasroot /usr/sbin/sshd --network --cap-default -- -p 8022:22 --
You need the container IP to access the ssh server. One possibility is to check the x11docker container info file:
read infofile < <(x11docker --printinfofile --runasroot /usr/sbin/sshd --network --cap-default -- -p 8022:22 -- IMAGE)
cat $infofile
ip="$(cat $infofile | grep containerip | cut -d= -f2)"
Access the container with:
ssh -Y $ip
Run a GUI. If it does not appear on your ssh client but on the X server of the container, than ssh did not set the environment variables properly. For that case x11docker provides a helper script in container /x11docker/sshenv. You can source it in your ssh shell to export the environment variables.
source /x11docker/sshenv
SSH setup with xpra allows detaching and reattaching to a remote session.
Example for an SSH setup with xpra:
- Server setup:
#! /bin/bash
# Run invisible Xvfb X server with display number :30.
# Catches X environment with 'read < <(...)' construct.
# Docker container runs on invisible Xvfb display.
# (for X server options other than --xvfb or --xdummy also add options --showenv and --xtest).
read Xenv < <(x11docker --xvfb --printenv --display=30 x11docker/lxde pcmanfm)
# Output of new X environment, just for info
# (You can drop `--display=30` in command above if you provide DISPLAY
# from this output to following xpra commands instead of :30)
echo $Xenv
# Start xpra server with new environment variables.
# (Replace "start" with "start-desktop" to forward a desktop environment)
env $Xenv xpra start :30 --use-display --start-via-proxy=no --daemon=no
- Client setup:
# Attach xpra client over SSH to xpra server.
# Replace SERVERIP with IP or host name of ssh server.
# You might need to specify a user name in the form USER@SERVERIP
xpra attach ssh://SERVERIP/30
You can detach the SSH connection and attach later again without terminating the container application:
xpra detach ssh://SERVERIP/30
You can stop xpra server without terminating x11docker:
xpra stop ssh://SERVERIP/30
A script entirely executed on client. (It will ask three times for ssh password, may be solved more nicely).
#! /bin/bash
HOSTNAME=localhost # Change to desired server address
IMAGECOMMAND="x11docker/lxde lxterminal" # Change to desired image name and command
# Runs x11docker on remote server. Reads new X environment variables from its output.
# (for X server options other than --xvfb or --xdummy add options --showenv --xtest).
read Xenv < <(ssh -f $HOSTNAME -- x11docker --xvfb --printenv $IMAGECOMMAND)
# extract DISPLAY from new X environment
Newdisplay=$(sh -c "export $Xenv ; echo \$DISPLAY")
# start remote xpra server
# (replace "xpra start" with "xpra start-desktop" for desktop environments)
ssh $HOSTNAME -- env $Xenv xpra start $Newdisplay --use-display --start-via-proxy=no
# start local xpra client
xpra attach ssh://$HOSTNAME/$Newdisplay
- If you have xpra version <2.4, don't try this on localhost due to an xpra memory bug.
- If your client does have a big display resolution or a multimonitor setup, xpra may scale up the size of forwarded windows. Check output of
xrandr | grep currentor xpra client output for your client display resolution. It may be e.g.2084x768. Add--size 2048x768tox11docker --xvfb [...]command to get a matching server display size.