2016-05-10

RustyCode Running on Docker in Azure & Displaying Locally

My last post showed how to run Visual Studio Code from a Docker container. I recommended installing an X Windows Server and using X11 forwarding over SSH, until I discovered Xpra this past week! It performs so much better, especially over my slow internet connection. Here is an 11 minute movie where I demonstrate running Code from a Docker container running a ctaggart/rusty-vscode image on a Azure VM. Code is running on Azure, but displaying on my Windows 10 laptop.


Xpra

"It allows you to run programs, usually on a remote host, direct their display to your local machine, and then to disconnect from these programs and reconnect from the same or another machine, without losing any state." It is awesome! There are clients for Windows, Mac OS X, and Linux. Download and install it. An X Windows Server like VcXsrv or XQuartz are not needed. Use Xpra instead.

Docker + VS Code + Xpra

I scripted the install of VS Code, the install of Xpra, and the install of RustyCode, a VS Code extension. You could run these or similar scripts inside of an existing container to create a development environment on demand. You can also create pre-bundled Docker images with these tools. I've now started three: rusty-vscodegolang-vscode, and dotnet-vscode. The movie above shows off ctaggart/rusty-vscode Docker image which has the latest RustyCode extension installed.

Azure VM with Docker

I simply selected the Docker on Ubuntu Server template.

I put it on an Azure A2 VM at less than 10 cents ($0.094) per hour and uploaded an SSH public key.

SSH on Windows

One of the easiest ways to currently use SSH on Windows is to use the Git Bash prompt that comes with Git for Windows. I launched Git Bash by running "C:\Program Files\Git\git-bash.exe". You then can follow GitHub's instructions for generating an ssh key. I recommend using a good passphrase to secure the private key. The public keys are meant to be shared. Feel free to add it to your GitHub account too.

Running the Docker Image

After creating the VM, you may ssh to it, run the Docker image, start Xpra, and start Code. I started Xpra server to listen on port 6100. We will redirect that port from the Docker container to the Azure VM, and tunnel it though SSH to expose it locally. We then have Xpra client connect to the port, which will allow any Windows started in the container to show up locally.

on server

ssh -L 6100:127.0.0.1:6100 [email protected]
docker run --rm -it -p 6100:6100 ctaggart/rusty-vscode
. start-xpra.sh
code .

Here is a screenshot of the first couple of commands, but you will need to forward the port like above and change the host you are connecting to. The SSH command tunnels local port 6100 to the Azure VM, so that the Xpra client will find the Xpra server. It is important that you source the start-xpra.sh script since it will set the DISPLAY environment variable. With that env var set, graphical apps will send their windows to the Xpra server. That code command just opens up VS Code in the current directory of /home/vscode. Feed free clone repositories like I did in the movie or use Docker volumes to mount code you are working on.


on local client if Windows and using PowerShell

$env:path="C:\Program Files (x86)\Xpra;$env:path"
xpra_cmd attach tcp:127.0.0.1:6100

on local client if Mac OS X

export PATH=/Applications/Xpra.app/Contents/MacOS:$PATH
xpra attach tcp:127.0.0.1:6100