Install Docker CE on Ubuntu 18.04 - 20.04

Updated on December 1, 2020
Install Docker CE on Ubuntu 18.04 - 20.04 header image

Introduction

Docker is an application that allows us to deploy programs that are run as containers. It was written in the popular Go programming language. This tutorial explains how to install Docker CE, and has been tested on:

  • Ubuntu 18.04 LTS
  • Ubuntu 18.10
  • Ubuntu 20.04 LTS

Uninstall old versions

Older versions of Docker were called docker, docker.io or docker-engine. If these are installed in your machine, uninstall them:

sudo apt-get remove docker docker-engine docker.io containerd runc

Updating all your software

Let’s make sure that we are using a clean system. Update the apt package index and upgrade:

sudo apt-get update && sudo apt-get upgrade -y

Set up the repository

Install packages to allow apt to use a repository over HTTPS:

sudo apt-get install 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

OUTPUT

pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]

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"

Install Docker CE

Update the apt package index:

sudo apt-get update

Install the latest version of Docker CE and containerd:

sudo apt-get install docker-ce docker-ce-cli containerd.io

Create a user

The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Create a non-root user which will be added to the docker group:

adduser user
usermod -aG docker user

Restart the Docker service:

systemctl restart docker

Test Docker

Run the Docker hello-world container to ensure that the installation completed successfully:

docker run hello-world

OUTPUT

Hello from Docker!

This message shows that your installation appears to be working correctly.

Configure Docker to start on boot

Lastly, enable Docker to run when your system boots:

systemctl enable docker

Congratulations, you have successfully installed Docker. To further explore Docker, visit the official documentation to get started.