How to Install Docker and Docker Compose on Ubuntu

0

How to Install Docker and Docker Compose on Ubuntu

To install Docker and docker compose on Ubuntu, run 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

Let’s break these Dockers down and docker compose Ubuntu installation steps in more detail.

Prerequisites of the Docker configuration example

The first set of Docker installation commands simply configure your Ubuntu instance with the required prerequisites of:

  • CURL – the utility 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 in use
  • 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

Configuring the Docker repository

Once the prerequisites are met, the Docker 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 uploaded to this 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

Once the key is downloaded, local references to the remote Docker repository can be set up by running this dauntingly 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 configure Docker and docker compose actually installs four pieces of software on Ubuntu:

  • DockerCE
  • The Docker CE command line interface
  • Container
  • The docker compose connect
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

This example installs Docker 20 on Ubuntu 22.

Test the example Docker configuration on Ubuntu

With Docker and docker compose installed, you can then issue various commands in the terminal window. Popular commands for testing Docker configuration on Ubuntu include:

docker composer install ubuntu

This example installs docker compose 2.5 on Ubuntu 22.

And it’s as easy as it is to configure and install Docker and docker compose on Ubuntu.

Share.

Comments are closed.