I’ve worked for the last 4 years in the financial market and I’m a heavy Excel user. I also use the browser a lot and since I started my summer job as financial intern at dotCloud I’ve been playing with docker. So, why don’t we take advantage of the cloud and use these and other heavy applications (in terms of processing and memory usage) within a container (lighter than a normal VM).
Let’s get started!
- On Linux:
Docker is available as a Ubuntu PPA (Personal Package Archive), hosted on launchpad which makes installing Docker on Ubuntu very easy.
# Add the PPA sources to your apt sources list. sudo apt-get install python-software-properties && sudo add-apt-repository ppa:dotcloud/lxc-docker # Update your sources sudo apt-get update # Install, you will see another warning that the package cannot be authenticated. Confirm install. sudo apt-get install lxc-docker
- On Mac: Installation Tutorial
- On Windows: Installation Tutorial
I used a Dockerfile in order to guarantee the integrity of the steps and also to automate the creation of the docker image. This Dockerfile creates a docker image that, once executed, generates a container that runs X11 and SSH services.
The ssh is used to forward X11 and provide you encrypted data communication between the docker container and your local machine.
Xpra + Xephyr allows to display the applications running inside of the container such as Firefox, LibreOffice, xterm, etc. with recovery session capabilities. So, you can open your desktop any where without losing the status of your applications, even if the connection drops.
Xpra also uses a custom protocol that is self-tuning and relatively latency-insensitive, and thus is usable over worse links than standard X.
The applications can be rootless, so the client machine manages the windows that are displayed.
creates a very minimalist way to manage files and icons on the desktop.
OBS: The client machine needs to have a X11 server installed (Xpra). See the “Notes” below.
Building the docker image
$ docker build -t [username]/docker-desktop git://github.com/rogaha/docker-desktop.git
The parameter [-t] gives you the ability to name the image that is going to be created from the GitHub repository that contains the Dockerfile. In this case, the image will be called rogaha/docker-desktop. This image has the docker-desktop (Xephyr+Fluxbox+ROX-filer), Firefox with Flash Player plugin, LibreOffice and xterm. You can either use xterm or the ssh terminal to install/uninstall other GUI applications and use them remotely.
Verifying the existing images
$ docker images REPOSITORY TAG ID CREATED SIZE base latest b750fe79269d 3 months ago 24.65 kB (virtual 180.1 MB) rogaha/docker-dektop latest 5b07bd6027bd 5 days ago 12.29 kB (virtual 1.39 GB) ubuntu 12.10 b750fe79269d 3 months ago 24.65 kB (virtual 180.1 MB)
As we can see the image rogaha/docker-desktop was created and is ready to run.
Running the docker image created
-d: detached mode
-P: expose all the ports to the host machine
$ CONTAINER_ID=$(docker run -d -P [username]/docker-desktop)
The environment variable $CONTAINER_ID contains the ID of the new running container created from the rogaha/docker-desktop image. The
-P was introduced with docker version
Getting the password generated during runtime
$ echo $(docker logs $CONTAINER_ID | sed -n 1p) User: docker Password: xxxxxxxxxxxx
A new password is generated by PWGen every time that a container is created. The password contains 12 characters with at least one capital letter and one number.
Getting the container’s external ssh port
$ docker port $CONTAINER_ID 22 49153 # This is the external port that forwards to the ssh service # running inside of the container as port 22
We are going to use this port later to connect to the machine where docker daemon is running.
Connecting to the container
Starting the a new session
First, we need to get the IP of the machine where docker is running.
$ ifconfig | grep "inet addr:" inet addr:192.168.56.102 Bcast:192.168.56.255 Mask:255.255.255.0 # This is the LAN's IP for this machine
Then, we connect to that IP using the external port that we got previously (49153) in order to start a new session inside of the container
$ ssh email@example.com -p 49153 ./docker-desktop -s 800x600 -d 10 firstname.lastname@example.org's password: xxxxxxxxxxxx $ ./docker-desktop -h ----------------------------------------------------------- Usage: docker-desktop [-s screen_size] [-d session_number] -s : screen resolution (Default = 800x600 -d : session number (Default = 10) -h : help -----------------------------------------------------------
Attaching to the session started
$ xpra --ssh="ssh -p 49153" attach ssh:email@example.com:10 # user@ip_address:session_number firstname.lastname@example.org's password: xxxxxxxxxxxx
If you want to execute rootless applications, you just need to connect to the container via ssh and type: DISPLAY=:[session_number] [program_name] &
Eg. DISPLAY=:10 firefox &
It took me only a few hours to create this Dockerfile and now I’m able to use it anywhere at any time and everything is configured and ready to run.
Developers can save a lot of time with docker by automating their workflow and normal users can take advantage of the cloud and run heavy applications remotely and save their local processing and memory usage.
If you have any questions, please feel free to contact me at email@example.com
- On Windows:
- On Mac:
- On Linux:
- Xpra: You can use apt-get to install it
$ sudo apt-get install xpra
- You can find the source code of this project on GitHub: https://github.com/rogaha/docker-desktop