Docker is a fantastic tool for running virtual images and managing light Linux containers extremely quickly.
One thing this has been very useful for in my job at Canonical is quickly running older versions of Ubuntu - for example to test how to install specific packages on Precise when I’m running Trusty.
Installing Docker
The simplest way to install Docker on Ubuntu is using the automatic script:
curl -sSL https://get.docker.io/ubuntu/ | sudo sh
You may then want to authorise your user to run Docker directly (as opposed to using sudo
) by adding yourself to the docker
group:
sudo gpasswd -a [YOUR-USERNAME] docker
You need to log out and back in again before this will take effect.
Spinning up an old version of Ubuntu
With docker installed, you should be able to run it as follows. The below example is for Ubuntu Precise, but you can replace “precise” with any available ubuntu version:
mkdir share # Shared folder with docker image - optional
docker run -v `pwd`/share:/share -i -t ubuntu:precise /bin/bash # Run ubuntu, with a shared folder
root@cba49fae35ce:/# # We're in!
The -v `pwd`/share:/share
part mounts the local ./share/
folder at /share/
within the Docker instance, for easily sharing files with the host OS. Setting this up is optional, but might well be useful.
There are some import things to note:
- This is a very stripped-down operating system. You are logged in as the root user, your home directory is the filesystem root (
/
), and very few packages are installed. Almost always, the first thing you’ll want to run isapt-get update
. You’ll then almost certainly need to install a few packages before this instance will be of any use. - Every time you run the above command it will spin up a new instance of the Ubuntu image from scratch. If you log out, retrieving your current instance in that same state is complicated. So don’t logout until you’re done. Or learn about managing Docker containers.
- In some cases, Docker will be unable to resolve DNS correctly, meaning that
apt-get update
will fail. In this case, follow the guide to fix DNS.