How to install Docker in Ubuntu 14.04 and up

Installing Docker in Ubuntu 14.04 and above is fairly easy. It just requires one line:

sudo apt-get install

Optionally, you may also want to use the docker command rather than

sudo ln -sf /usr/bin/ /usr/local/bin/docker

To get an Ubuntu image running inside your Ubuntu OS:

sudo pull ubuntu
sudo run -i -t ubuntu /bin/bash

The first command downloads a Docker container for an Ubuntu system. The second command launches this container with a Bash shell inside it. The option -t allocates a terminal, -i attaches stdin and stdout to it. Once you exit the shell, the Docker image will be switched off.

Alternatively, you may want to launch a specific version of Ubuntu: a container can contain multiple images. This command shows the available images that you have downloaded so far:

sudo images

Excerpt of the result:

REPOSITORY          TAG                 IMAGE ID
ubuntu              vivid               76ca2fd90787
ubuntu              15.04               76ca2fd90787
ubuntu              utopic              cfaba6b5fefe
ubuntu              14.10               cfaba6b5fefe
ubuntu              14.04               5ba9dab47459
ubuntu              trusty              5ba9dab47459
ubuntu              14.04.1             5ba9dab47459
ubuntu              latest              5ba9dab47459
ubuntu              12.04.5             69c02692b0c1

When launching without specifying an image version, Docker launches the image that has the latest TAG. You can check with the IMAGE ID column to which it corresponds actually. Inside the Ubuntu container, you can also launch this command in order to check the version:

root@daa88df2d9ad:/# cat /etc/lsb-release

Now if you want to launch another version, you can simply preprend the TAG of the version you want to launch to the container in this way:

sudo run -i -t ubuntu:12.04.5 /bin/bash

A check of the version shows now:

root@04ecc1b35fe8:/# cat /etc/lsb-release 
This entry was posted in Tips and tricks and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s