Skip to Content

How to Install Docker and Docker Compose on Ubuntu 20.04

This tutorial will show you how to install the latest version of Docker and Docker Compose on Ubuntu 20.04. We’ll also configure the system, so you don’t need to use sudo to run Docker commands.

Note: The steps in this tutorial show you how install Docker manually. Read How to install Docker with Ansible to learn how to automate the process.

Prerequisites

Before we begin you’ll need access to a clean installation of Ubuntu 20.04. This tutorial shows you how to install it on VMware Fusion (or VMware Workstation if you’re a Windows or Linux user).

You may also want to update your packages to the latest versions by running:

sudo apt update && sudo apt upgrade -y

Step 1: Install Dependencies

Run the following command to install the required dependencies.

sudo apt install -y /
apt-transport-https /
ca-certificates /
curl /
software-properties-common /
gnupg-agent

Step 2: Add Docker Signing Key

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

Verify the key is correct by running the following command and checking the output matches 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88:

sudo apt-key fingerprint 0EBFCD88
ubuntu@ubuntu:~$ 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 Docker Stable Repository

Run the following command to add the stable Docker repository to /etc/apt/sources.list

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

Update package information:

sudo apt-get update

Step 4: Install Docker

Run the following command to install Docker:

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

Step 5: Add User to Docker group

The last step is to add your local user to the docker group so that you don’t need to use sudo when running Docker commands. Run the following command to add it to the group:

sudo usermod -a -G docker $USER

Sign out then back in for the changes to take effect. You should now be able to run an image without using sudo. You can test this by running the hello-world image:Advertisements

docker run --rm hello-world
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
Status: Downloaded newer image for hello-world:latest

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/

Installing Docker Compose

Docker Compose can be installed with apt by running:

sudo apt install docker-compose

However, using apt will not install the latest version. You can install the latest with curl by running the following commands:

curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /tmp/docker-compose
chmod +x /tmp/docker-compose
sudo mv /tmp/docker-compose /usr/local/bin/docker-compose

Note: replace 1.27.4 in the URL above with the version you want to install.

Conclusion

In this tutorial we installed the latest version of Docker and Docker Compose on Ubuntu Linux 20.04.

These steps are good for one time installations, but if you’ve got hundreds of servers to configure, you might want to automate this process. This tutorial will show you how to automate the installation of Docker with Ansible.