Docker installation

Share this post on:

Prerequisites

sudo apt update
sudo apt install \
ca-certificates \
curl \
gnupg \
lsb-release

Add official Docker’s GPG key

# Detect the Linux distribution
. /etc/os-release

# Download Docker's GPG key based on the distribution
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
    curl -fsSL https://download.docker.com/linux/$ID/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
else
    echo "Unsupported distribution: $ID"
    exit 1
fi

# Set permissions for the GPG key
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
fi

# Set up the Docker repository
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$ID $VERSION_CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt update --allow-insecure-repositories
fi

Install Docker engine

sudo apt --allow-unauthenticated install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Receiving a GPG error when running ‘apt update‘?

Your default umask may not be set correctly, causing the public key file for the repo to not be detected. Run the following command and then try to update your repo again: ‘sudo chmod a+r /etc/apt/keyrings/docker.gpg‘.

Run ‘docker‘ without ‘sudo‘

sudo groupadd docker
sudo usermod -a -G docker $USER
groups
grep docker /etc/group
newgrp docker

Validate installation

sudo docker run hello-world
Share this post on:

Author: tayyebi

Tayyebi works in the role of Director at Gordarg where he is the founder. He is passionate about people, technology, and arts. Mohammad believes in communications, each of us has the power to empower their people with knowledge. He can be seen writing codes, playing music, biking, and reading.

View all posts by tayyebi >






www.Gordarg.com