Install Docker and Docker Compose on Ubuntu Linux

apps on screen
apps on screen

The post provides a detailed tutorial on how to install Docker and Docker Compose on Ubuntu Linux. Docker, a software platform developed by Docker Inc., allows system-level virtualization and runs applications as containers. Docker Compose is a tool used for defining and running multi-container Docker applications. Instructions are given for adding Docker’s official GPG key and repository to Ubuntu, removing older versions, installing specific or latest versions of Docker, and finally installing Docker Compose.

This post shows students and new users how to install Docker and Docker Compose on Ubuntu Linux.

Docker software allows virtualization at the operating system level. Unlike VirtualBox and VMware Workstation, you run virtual applications as containers. Docker Inc developed Docker and runs software packages as containers, making building applications quickly shared and running anywhere.

Docker Compose is a tool for defining and running multi-containers Docker applications. It uses YAML files to configure application services, then with a single command using the definitions in the file to start these services based on the configurations.

If you want to build an environment on Ubuntu to build Docker containers, you’ll want to install Docker and Docker Compose to make your job easier.

How to add Docker repository on Ubuntu Linux

Docker has two editions:  The Enterprise Edition (EE) and the Community Edition (CE).

For this tutorial, we will install the community edition of Docker.

If you always want to get the latest version of Docker on Ubuntu automatically, you must add its official repository to the Ubuntu system. To do that, run the commands below to install prerequisite packages.

sudo apt update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Next, run the commands below to download and install Docker’s official GPG key. The key is used to validate packages installed from Docker’s repository, ensuring they’re trusted.

curl -fsSL | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88

You should see an output shown below:

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]

Now that the official GPG key is installed, run the commands below to add its stable repository to Ubuntu. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below.

sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"

At this point, Docker’s official GPG and repository should be installed on Ubuntu.

For those who currently have older versions of Docker, run the commands below to remove them.

sudo apt remove docker docker-engine containerd runc

When you have removed all previous versions of Docker, run the commands below to install the latest and current stable version of Docker.

To install a specific version of Docker, run the apt-cache command. Then select the version to install.

apt-cache madison docker-ce

docker-ce | 5:18.09.5~3-0~ubuntu-bionic | bionic/stable amd64 Packages
docker-ce | 5:18.09.4~3-0~ubuntu-bionic | bionic/stable amd64 Packages
docker-ce | 5:18.09.3~3-0~ubuntu-bionic | bionic/stable amd64 Packages
docker-ce | 5:18.09.2~3-0~ubuntu-bionic | bionic/stable amd64 Packages

Now to install a specific version, run the commands below with the version you wish to install

sudo apt-get install docker-ce=5:18.09.5~3-0~ubuntu-bionic docker-ce-cli=5:18.09.5~3-0~ubuntu-bionic

If you want the latest version without specifying the above, run the commands below. The command below will always install the highest possible version.

sudo apt update
sudo apt install docker-ce docker-ce-cli

That should install Docker software on Ubuntu.

Verify that Docker CE is installed correctly by running the hello-world image, run the commands below:

sudo docker run hello-world

You should see a similar line below:

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

Docker is installed correctly!

How to install Docker Compose on Ubuntu Linux

On Ubuntu Linux, you can download the Docker Compose binary from the Compose repository release page on GitHub.

To install it, run the commands below to download version 1.24.0. As of this writing, this is the current version.

sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

To install a different version of Compose, substitute 1.24.0 with the version of Compose you want to use.

After downloading it, run the commands below to apply executable permissions to the binary file and create a symbolic link to /usr/binary

sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

That should get Docker Compose working. To test, run the commands below:

docker-compose --version

You should see similar output as below:

docker-compose version 1.24.0, build 0aa59064

That should do it!

To run Docker as a non-root user, add your user account to Docker’s group by running the commands below:

sudo usermod -aG docker $USER

Log out and back in, and you should be able to run Docker with your standard account.


This post showed you how to install Docker and Docker Compose on Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.

Posted by

I love computers; maybe way too much. What I learned I try to share at

1 Comment

  1. 06/23/2020 – On your main page, and under Docker, you state:

    “Docker software allows visualization at the operating system level..”

    You mean “virtualization” not visualization, and there’s two periods at the end of that same sentence.

    just sayin…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.