Install Docker on Ubuntu 16.04 Xenial Xerus

In this tutorial, we will see how to install the official version of Docker on Ubuntu 16.04 Xenial Xerus in a simple and fast way.

Included in Ubuntu 16.04 Xenial Xerus is already available version 1.6.1 of Docker packaged for deployment, but in this article, we will find out how to install the version available on the site that is up to date.

Ubuntu Xenial installation is pretty easy: the first thing to do is update the list of packages in your distribution.

apt-get update

Then add Docker’s repository key to your operating system.

sudo curl -fsSL | sudo apt-key add -

Add official stable Docker repositories.

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

update the system by issuing the following command,

sudo apt-get update

Make sure docker official repositories are added and used instead of default Ubuntu.

sudo apt-cache policy docker-ce

You will receive following output whcih shows that official resposatories are used for docker,

mani@host:~$ apt-cache policy docker-ce
 Installed: (none)
 Candidate: 17.06.2~ce-0~ubuntu
 Version table:
 17.06.2~ce-0~ubuntu 500
 500 xenial/stable amd64 Packages
 17.06.1~ce-0~ubuntu 500
 500 xenial/stable amd64 Packages
 17.06.0~ce-0~ubuntu 500
 500 xenial/stable amd64 Packages
 17.03.2~ce-0~ubuntu-xenial 500
 500 xenial/stable amd64 Packages
 17.03.1~ce-0~ubuntu-xenial 500
 500 xenial/stable amd64 Packages
 17.03.0~ce-0~ubuntu-xenial 500
 500 xenial/stable amd64 Packages

Now we install Docker

sudo apt-get install -y docker-ce

At this point docker group automatically added to our system. All you need to add your desired user with sudo power to run the docker without typing sudo every time. Change “mani” with your username.

sudo usermod -aG docker mani

Activate OverlayFS for Docker on Ubuntu 16.04 Xenial Xerus

This step is completely optional but allows you to use Docker with a different driver and file system than the standard ones.

READ  Clam AV-Linux AntiVirus

If you wish, you can use a different disk for Docker images and containers. Suppose you want to keep the root filesystem separate from the image files and containers.

Prepare the new disk by creating a new partition by replacing sdb with the device you decided to allocate to Docker:

sudo fdisk /dev/sdb

Once you’ve created the partition, format it with the ext4 format.

sudo mkfs -t ext4/dev/sdb1

We create the /var/lib/docker/overlay folder

sudo mkdir -p /var/lib/docker/overlay

Now insert in the /etc/fstab file the necessary information for the disk to be mounted in the folder at each reboot of Ubuntu 16.04.

sudo nano /etc/fstab

Add the line

/dev/sdb1/var/lib/dockers/overlay ext4 defaults, nofail 0 2

Let’s remember to replace /dev/sdb1 with the partition created for Docker or with the UUID assigned to that partition. You can find out the UUID using the command:

sudo blkid

I show you how my file /etc/fstab was made after editing:

At this point, we mount the file system.

sudo mount -a

Then open the /etc/default/docker file to indicate that you use overlay and custom folder.

sudo nano /etc/default/docker

Insert the following line at the bottom of the file:

DOCKER_OPTS = "- s Overlay -g /var/lib/docker/overlay"

We save the file.

Let’s restart Docker.

sudo service docker restart