How to install Docker and docker compose on Ubuntu

How to install Docker and docker compose on Ubuntu

For those who are just looking for the commands to run to install Docker and docker compose on Ubuntu, here they are all listed together. We will go into more detail on how these commands work and what these commands do in subsequent sections.

To install Docker and docker compose on Ubuntu, issue the following commands in a terminal window:

### Docker and docker compose prerequisites
sudo apt-get install curl
sudo apt-get install gnupg
sudo apt-get install ca-certificates
sudo apt-get install lsb-release
### Download the docker gpg file to Ubuntu
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

### Add Docker and docker compose support to the Ubuntu's packages list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-pluginsudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-pluginlinux/ubuntu   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
 
### Install docker and docker compose on Ubuntu
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
 
### Verify the Docker and docker compose install on Ubuntu
sudo docker run hello-world

Docker and compose install steps on Ubuntu

Let’s break down these Docker and docker compose install command for Ubuntu into more detail. Here are the basic steps you need to follow to install Docker and docker compose on Ubuntu:

  1. Install the prerequisite software
  2. Download Docker GPG file
  3. Configure the Docker software repository
  4. Install Docker along with Containerd and the docker compose plugin
  5. Validate the Docker and docker compose setup

Docker setup example prerequisites

The first set of Docker install commands simply configures your Ubuntu instance with the required prerequisites of:

  • CURL – the utility which is used to download the Docker GPG key
  • GnuPG – a free implementation of OpenPGP to work with the Docker GPG key.
  • The lsb-release command to identify the Linux distribution currently being used
  • Certificate Authority support
sudo apt-get install curl 
sudo apt-get install gnupg 
sudo apt-get install ca-certificates 
sudo apt-get install lsb-release

Docker repository configuration

After the prerequisites are met, the Docker’s GNU Privacy Guard key must be downloaded, after which Ubuntu’s references to the Docker software repository can be updated.

The following two commands first create a folder to hold the Docker GPG file, after which the key is downloaded into that folder.

sudo mkdir -p /etc/apt/keyrings 
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

After the key is downloaded, the local references to the remote Docker repository can be configured by issuing this intimidatingly long command:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Docker and Docker compose install command

The command to setup Docker and docker compose actually installs four pieces of software on Ubuntu:

  • Docker CE
  • The Docker CE command line interface
  • Containerd
  • The docker compose plugin
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
docker install on Ubuntu

This example installs Docker 20 on Ubuntu 22.

Test the Docker setup example on Ubuntu

With Docker and docker compose installed, you can then issue various commands in the terminal window. Popular commands to test the Docker setup on Ubuntu include:

  • sudo docker --version
  • docker compose version
  • sudo docker run hello-world
  • sudo docker images
  • sudo docker ps -a
docker compose install ubuntu

This example installs docker compose 2.5 on Ubuntu 22.

And that’s how easy it is to setup and install Docker and docker compose on Ubuntu.

SearchAppArchitecture
SearchSoftwareQuality
SearchCloudComputing
SearchSecurity
SearchAWS
Close