May 8, 2022 2 min read

How To Install Docker and Docker-Compose On Ubuntu Linux

In this tutorial, we are going to install docker and docker-compose on either a raspberry pi4 running Ubuntu Linux or an AMD64 system running Ubuntu Linux.

How To Install Docker and Docker-Compose On Ubuntu Linux
Table of Contents

In this tutorial, we are going to install docker and docker-compose on either a raspberry pi4 running Ubuntu Linux or an AMD64 system running Ubuntu Linux.

What is Docker and Docker-Compose?

Docker is open-source container software that enables you to package your software inside a container making use of the operating system kernel and isolated from the host computer services. You can build and store your own docker containers on Dockerhub and share them with the rest of the open-source communities. Docker-compose is a tool to help manage multi-container deployments.

Install Docker and Docker-Compose:

Install docker and docker-compose with the scripts below, use Arm64 if you are running Ubuntu on a Raspberry PI4 and 86_64 if you are an Intel Processor type:

Create a shell script to paste the bash code:

sudo nano docker-install.sh

Copy to bash file for Raspberry PI4:

#!/bin/bash

# Install Docker on Ubuntu Server on Raspberry PI ARM64
# source http://docs.docker.com/engine/install/ubuntu/

echo "Updating apt package index..."
sudo apt update
sleep 10s
yes | sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
    
echo "Adding Docker official GPG key..."
curl -fsSL http://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sleep 10s
echo "Adding Docker to apt repository..."
echo \
"deb [arch=arm64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] http://download.docker.com/linux/ubuntu \

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sleep 10s
echo "Updating System ...."
sudo apt update
sleep 10s
echo "Installing Docker and ContainerD ...."
yes | sudo apt install docker-ce docker-ce-cli containerd.io
sleep 5s
echo "Docker Installation completed!!!"
sleep 5s
echo "Installing Docker Compose...."
yes | sudo apt install docker-compose
echo "Docker Compose Installation Completed!"
docker --version
docker-compose --version

## add current user to docker group
sudo usermod -aG docker $USER

Copy bash file for x86_64 Systems:

#!/bin/bash

# Install Docker on Ubuntu Server x86_64/AMD64
# source http://docs.docker.com/engine/install/ubuntu/

echo "Updating apt package index..."
sudo apt update
sleep 10s
yes | sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

echo "Adding Docker official GPG key..."
curl -fsSL http://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
sleep 10s

echo "Adding Docker to apt repository..."
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] http://download.docker.com/linux/ubuntu \

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sleep 10s
echo "Updating System ...."
sudo apt update
sleep 10s
echo "Installing Docker and ContainerD ...."
yes | sudo apt install docker-ce docker-ce-cli containerd.io
sleep 5s
echo "Docker Installation completed!!!"
sleep 5s

echo "Installing Docker Compose...."
yes | sudo apt install docker-compose
echo "Docker Compose Installation Completed!"
docker --version
docker-compose --version

## add current user to docker group
sudo usermod -aG docker $USER

Add execution permissions in order to run the bash script and install docker and docker-compose:

sudo chmod +x docker-install.sh

Run the script to install docker and docker-compose:

./docker-install.sh
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Opensource Geeks.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.