Docker on VirtualBox installation commands

This is a short howto about setting up VirtualBox with a Docker environment in it.

Set up a clean Debian VM with the regular install, a 10G disk, and nothing but the SSH server packages. (I have started to just use the Vagrant setup, which uses the username vagrant and password vagrant, in case I want to convert it to a Vagrant image.) Download the VirtualBox Guest Additions CD and, as root, do these things to prep the virtual box to install the drivers.

Run the following. I tend to do them all on one line, but sometimes, that fails.

apt-get install sudo
apt-get install gcc
apt-get install make
apt-get install linux-headers-$(uname -r)
apt-get install bzip2
apt-get install apt-transport-https
apt-get autoclean

Then insert the Guest Additions CD into the vm, and do this:

mkdir cd
mount /dev/cdrom cd
cd cd
./VBoxLinux[tab]
cd ..
umount cd
rmdir cd

At this point, you have a pretty lean box and should not touch it anymore. Make a clone of this VM and start it up. (Use the menu Machine->Clone… and then choose Linked Clone. This creates one with a smaller virtual disk.)

Then install Docker.

You can “cheat” by making a shared folder called “docker”, pointing to a folder on your disk. Mount that with this command:

mkdir docker
mount -t vboxsf docker docker

Then, paste this into a text file within the shared folder, and execute it with the shell.

apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo deb https://apt.dockerproject.org/repo debian-jessie main > /etc/apt/sources.list.d/docker.list

Then run the following:

apt-get update
apt-cache policy docker-engine
apt-get install docker-engine
service docker start
docker run hello-world
shutdown now

Then, make a clean snapshot of this Docker image, so you can rewind back to it.

Why did we make a clone?

So we could have this image around to make non-Docker VMs. Docker takes a lot of space.

Why install the Guest Additions?

To get the shared folders. There’s no easy way to copy-paste the long keyserver line.