Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu 16.04 - Install Docker

Install Using PPA

Using a PPA will allow you to always use the latest version of Docker without waiting on the Ubuntu package maintainers. Normally I would recommend installing from the Ubuntu Repos, but with docker this method is what I recommend.

Docker will not start correctly if you are running a VPN connection. This will make it appear like installation failed when actually installation succeeded but docker will fail to start up correctly.

Method 1

#!/bin/bash

# Stop script on any error
set -e

# Remove any existing installations...
sudo apt-get purge docker-engine -y
sudo apt-get remove docker docker-engine docker.io -y

sudo apt update 
sudo apt install -y \
software-properties-common apt-transport-https ca-certificates curl

# Add the key for docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

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

sudo apt update
sudo apt install docker-ce -y

# Add the current user to docker so that you can
# execute docker commands without using sudo
sudo usermod -aG docker $USER

echo "You will need to reboot before using docker."

I recommend checking and ensuring the storage driver is set to overlay2.

(Method 2)

This method is what I had been using for quite some time now and still works but the documentation now shows the method above.

Run the command below to install Docker through prog-exec.

prog-exec "7" "8260fb8f1d266abb3275b651e8e24f611751803046c1c9cd1741f98580f907ff"

... or you can execute the following script:

#!/bin/bash
sudo apt update -y
sudo apt install apt-transport-https ca-certificates -y

sudo apt-key adv \
--keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D

echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" \
| sudo tee /etc/apt/sources.list.d/docker.list


sudo apt update
sudo apt-get purge lxc-docker

sudo apt install -y docker-engine

# Add the current user to docker so that you can
# execute docker commands without using sudo
sudo usermod -aG docker $USER

echo "You will need to reboot before using docker."

Uninstall

If you wish to uninstall docker after having installed it using this method, use the commands below:

sudo apt-get purge docker-engine -y
sudo apt-get autoremove --purge docker-engine
sudo rm -rf /var/lib/docker 

Removing /var/lib/docker will remove all images, containers, and volumes, so move any data you want to keep before doing this!

Install From Ubuntu Repos

sudo apt update && sudo apt install docker.io -y

# Add our current user to the docker group so they can execute docker commands.
sudo usermod -a -G docker $USER

This will install version 1.10.3 at the time of writing this tutorial.

References

Last updated: 8th August 2020
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch