In this post, I will show you how to install Docker on Ubuntu Server 16.04 to enable apps in containers. Confused or don’t know what I am talking about? Please read my previous post on what is docker and how it compares to Virtual Machines. In short, Docker is a new way of running applications on your server by using less resources than a standard setup. It allows users to install applications inside Docker containers and run them effortlessly, isolated from the OS. The isolation helps destroy and create app containers in minutes without affecting the base OS. Due to this containerization has been increasing in popularity. Without further ado, let us see how to easily install Docker on Ubuntu 16.04 variants, including Server edition.

Install Docker on Ubuntu

It takes only a few simple steps to setup Docker on Ubuntu: add sources, install prerequisites, and finally install docker engine. In this Ubuntu Docker installation guide, I have broken this down to smaller steps to help you. Ready to roll? Open your commandline terminal and proceed.

Before you begin, enable Intel VT-x hardware virtualization in BIOS or UEFI firmware. This is required for Docker to run.

1. Update Sources and Install Docker Pre-requisites

To setup Docker on Ubuntu, run the following commands in sequence to update package information, install appropriate CA certificates, and install pre-requisites. For Ubuntu 16.04 we will install the linux-image-extra-* kernel packages as well.

sudo apt update sudo apt install apt-transport-https ca-certificates sudo apt install linux-image-extra-$(uname -r) linux-image-extra-virtual

2. Add Docker Source

Next, to download and install Docker on Ubuntu Linux, you need to add Docker repository and a key to access it. Add the GPG key using the following command:

sudo apt-key adv –keyserver hkp:// –recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Then, add the Docker repository for Ubuntu 16.04:

echo deb ubuntu-xenial main sudo tee /etc/apt/sources.list.d/docker.list

3. Setup Docker on Ubuntu

Now you are ready for Ubuntu Docker installation. First, update APT package index:

sudo apt update

Next, verify if APT is connecting to the correct Docker repository:

apt-cache policy docker-engine

You should see an output like what is shown below:

[caption id=”attachment_961” align=”alignnone” width=”740”] APT Policy results if using the correct repo.[/caption]

Finally, install Docker on Ubuntu using the following command:

sudo apt install docker-engine

4. Start and Verify Docker

Now that docker installation on Ubuntu is complete, start it using the following command:

sudo service docker start

Finally, verify if Docker is installed correctly by running the following command:

sudo docker run hello-world

You should see an output like what is shown below:

[caption id=”attachment_962” align=”alignnone” width=”740”] Confirmation that Docker is installed correctly.[/caption]

5. Configure Docker to start on boot

Docker does not automatically start during booting on Ubuntu. Ubuntu uses systemctl to autostart services. In order to configure Docker to autostart on boot, run the following command:

sudo systemctl enable docker

After running the command, Docker will start automatically after each system reboot.