How to Install Docker on Ubuntu 16.04 / Ubuntu 17.10 / Ubuntu 14.04

1
Install docker on Ubuntu 16.04
Install Docker on Ubuntu 16.04

Docker is an open source software that helps to deploy, run applications in a container. The containers are like a virtual machine but consume fewer resource, easy to manage and will always run the same regardless of operating environment it is running in.

Docker uses cgroups and namespace to allow the independent containers to run within a single Linux instance.

This guide will help you to install Docker on Ubuntu 16.04 / Ubuntu 17.10 / Ubuntu 14.04.

Docker requires 64-bit operating system and supports Ubuntu 16.04 / 17.10 and Ubuntu 14.04.

Docker Editions

Docker is now available in two editions,

  • Community Edition (CE)
  • Enterprise Edition (EE)

Here, we will install Docker Comunity Edition (CE).

Prerequisites

Uninstall older versions of Dockers, named “docker” or “docker-engine” along with associated dependencies. If your system does not have a docker package, skip the below step.

$ sudo apt-get -y remove docker docker-engine

Contents such as images, volumes, and networks under /var/lib/docker/ are preserved.

Install the below packages only on Ubuntu 14.04 to make use of aufs storage driver, make sure your system has the linux-image-extra package.

$ sudo apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual

Setup Docker Repository

Update the repository cache.

$ sudo apt-get update

Install the below packages to ensure the “apt” work with https method, and that CA certificates are installed.

$ sudo apt-get install -y apt-transport-https software-properties-common ca-certificates curl

Add the GPG key for Docker repository on your system.

$ wget https://download.docker.com/linux/ubuntu/gpg 
$ sudo apt-key add gpg

Now, add the official Docker repository by running the following command in the terminal.

### Ubuntu 16.04 ###

$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" | sudo tee /etc/apt/sources.list.d/docker.list

### Ubuntu 17.10 ### 

$ echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable" | sudo tee /etc/apt/sources.list.d/docker.list

#### Ubuntu 14.04 ###

echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu trusty stable" | sudo tee /etc/apt/sources.list.d/docker.list

Update the apt database.

$ sudo apt-get update

Make sure you are installing the docker from the official repository, not from the default Ubuntu 16.04 / 14.04 repo.

$ sudo apt-cache policy docker-ce

You should see the output like below, should have Docker repository details.

docker-ce:
  Installed: (none)
  Candidate: 17.03.1~ce-0~ubuntu-xenial
  Version table:
     17.03.1~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
     17.03.0~ce-0~ubuntu-xenial 500
        500 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

Install Docker on Ubuntu

Now, install the Docker using the following command.

$ sudo apt-get -y install docker-ce

Now you have Docker installed on your machine, start the Docker service in case if it is not started automatically after the installation

$ sudo systemctl start docker.service
$ sudo systemctl enable docker.service

Run a docker container to verify the Docker installation

$ sudo docker run hello-world

You should see output like below; this confirms us that Docker is correctly installed.

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

Allow Non-root user to run Docker

By default, you would require root privilege to run docker commands. To avoid this, I had been using docker commands with sudo. If you want to allow non-root users to run Docker containers, follow the below steps to give them privileges to run a Docker.

Create a group called docker if it does not exist.

$ sudo groupadd docker

Add your user to docker group, replace “raj” with your username.

$ sudo useradd raj

Add a user to docker group.

$ sudo usermod -aG docker raj

Log out and log back in.

Now, you should now be able to run Docker commands without prefixing sudo.

$ docker run hello-world

Here are some interesting tutorials for you to get started:

1: Top Important Docker Commands – Working with Docker Containers

2: Working with Docker Images – Building Docker Images

3: How to Build Docker Images with DockerFile

Docker Advanced Topics:

1: How to Setup Docker Private Registry on CentOS 7 / Ubuntu 16.04 / Fedora 27/26

2: How to Install and Configure Docker Swarm on CentOS 7 / Ubuntu 16.04 / Fedora 27/26

That’s All.

You might also like

How to Install Docker on Ubuntu 16.04 / Ubuntu 17.10 / Ubuntu 14.04

1