Computer Science Atlas
Step-By-Step

Ubuntu: Install Docker

January 16, 2021|Updated March 8, 2021
 
Table of Contents

Overview

These instructions work on Ubuntu versions 20.10 (Groovy), 20.04 (Focal), 18.04 (Bionic) and 16.04 (Xenial).

Step 1. Open a Terminal Session

If you're using an Ubuntu laptop or desktop, you can press Ctrl + Alt + T on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.

Step 2. Set Apt to Trust Docker's Repo

Download Docker's Apt repo key:

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

Verify the fingerprint of the key you just downloaded by running the command below, and making sure the output matches the output shown here.

sudo apt-key fingerprint 0EBFCD88
$ sudo apt-key fingerprint 0EBFCD88
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) 
sub   rsa4096 2017-02-22 [S]

Step 3. Add the Docker Apt Repo

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

Step 4. Install Docker using Apt

sudo apt update -y sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose
$ sudo apt update -y
$ sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose

Step 5. Test the Installation

Run a Docker command to test that the installation worked:

sudo docker ps
$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Step 6. Allow the Current User to Use Docker Commands

In the previous step, you had to use sudo in front of the docker command. To get rid of this requirement, first add the current user to the docker user group:

sudo groupadd docker sudo gpasswd -a $USER docker
$ sudo groupadd docker
$ sudo gpasswd -a $USER docker

Then exit the current terminal session:

exit
$ exit

The next time you login, you will be able to run Docker commands without sudo.

Congratulations!

You are now ready to use Docker on your machine.