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 Intel 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 https://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 https://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] https://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 to bash file for Intel:

#!/bin/bash

# Install Docker on Ubuntu Server x86_64/AMD64

# source https://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 https://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] https://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

## check docker control groups

if grep -q docker /proc/1/cgroup;then

   echo inside docker

else

   echo on host

   exit

fi

## 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

sudo ./docker-compose.sh
Liked it? Take a second to support Chad Crouch on Patreon!

Chad Crouch

Chad is a Software/DevOps Engineer with exposure and experience in various technologies and enterprise ICT environments. He has a huge passion for Technologies, specifically Linux and Open Source Software. If you enjoy our articles please support us and make a small contribution: Buy Us A Coffee