How To Install Docker and Docker-compose | Ubuntu 20.04

There are other ways to do it (please avoid using snap), however this is a proper one.

Steps:

sudo apt update
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common wget
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo  apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
sudo apt install -y docker-ce docker-compose

Add user to a docker group:

sudo usermod -aG docker $USER

Logout and login for docker group to be activated.

Or put it in the script: install_docker.sh and run with sh install_docker.sh

#!/bin/bash

# Tested on ubuntu 20.04

sudo apt update || echo "update failed"    # optional && apt upgrade -y

# installing docker and docker-compose

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common wget

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo  apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

sudo apt update

sudo apt install -y docker-ce docker-compose || echo "docker install failed"
sudo usermod -aG docker $USER

echo "docker has been installed! logout and login back in for docker group to be activated"

To enable swarm just run:

docker swarm init