DEV Community

Saravanan Gnanaguru
Saravanan Gnanaguru

Posted on • Updated on

Install Docker on Ubuntu 16.04

Introduction

  • We will see how to install docker on Ubuntu 16.04, in this article
  • Purpose of this tutorial is to provide the comprehensive steps focusing on the installation and verification of Docker on Ubuntu

Steps to Install Docker Explained

Setup the Repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install  apt-transport-https ca-certificates curl     gnupg-agent software-properties-common
Enter fullscreen mode Exit fullscreen mode

Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Enter fullscreen mode Exit fullscreen mode
# Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

sudo apt-key fingerprint 0EBFCD88
Enter fullscreen mode Exit fullscreen mode

Set up the stable repository:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
Enter fullscreen mode Exit fullscreen mode

Install Docker Engine

# Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode

Verify that Docker Engine Installation

# Verify Dockeris installed correctly by running the hello-world image.
sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Installation as Shell Script

# SET UP THE REPOSITORY
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update -y 
sudo apt-get remove -y docker docker-engine docker.io containerd runc
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common

# Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88, 
# by searching for the last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Use the following command to set up the stable repository. 
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

# Update the apt package index, and install the latest version of Docker Engine and containerd, 
# or go to the next step to install a specific version:
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

# Verify that Docker Engine is installed correctly by running the hello-world image.
sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Docker run output of Hello World

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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
Enter fullscreen mode Exit fullscreen mode

Bibliography

This article is inspired from the Docker installation documentation

Top comments (3)

Collapse
 
davidmaceachern profile image
David MacEachern

Hey Saravanan,

Have you considered whether your Docker installation has exposed ports on localhost on Ubuntu? It's something that's being tracked on this issue github.com/docker/for-linux/issues...

Collapse
 
chefgs profile image
Saravanan Gnanaguru

Thanks David. Definitely I’ll have look into it.

I’m learning Kubernetes using minikube so as part of learning I’ve created this Docker installation script. So thought of creating a post .

Collapse
 
davidmaceachern profile image
David MacEachern

Awesome! Looking forward to more!