How to install Docker Compose and Docker Engine 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:

  • 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, you must download the Docker’s GNU Privacy Guard key, and then update Ubuntu’s references to the Docker software repository.

The following two commands first create a folder to hold the Docker GPG file, and then download the key 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, configure the local references to the remote Docker repository with 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

This example installs Docker 20 on Ubuntu 22.

Test the Docker setup example on Ubuntu

Once you install Docker and docker compose, you can 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

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.

Be the first to comment

Leave a Reply

Your email address will not be published.


*