How to install Docker in Ubuntu 14.04 and up

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

sudo apt-get install docker.io

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

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

To get an Ubuntu image running inside your Ubuntu OS:

sudo docker.io pull ubuntu
sudo docker.io 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 docker.io 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
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

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 docker.io run -i -t ubuntu:12.04.5 /bin/bash

A check of the version shows now:

root@04ecc1b35fe8:/# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.5 LTS"
Advertisements

About nidget

Technology enthousiast, Java and JEE expert, IT architect.
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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s