Skip to content

Instantly share code, notes, and snippets.

@iklobato
Last active January 5, 2024 02:54
Show Gist options
  • Save iklobato/9219ac78dba102b2a6c0d0e786fb16ae to your computer and use it in GitHub Desktop.
Save iklobato/9219ac78dba102b2a6c0d0e786fb16ae to your computer and use it in GitHub Desktop.
Docker installation on ubuntu, single script
##############################################################################
# Docker Installation Script for Ubuntu #
# #
# Automates the installation of Docker on Ubuntu systems. Checks if Docker #
# is already installed; if not, it proceeds with the installation steps. #
# #
# This script simplifies Docker installation on Ubuntu by updating package #
# lists, installing necessary dependencies like ca-certificates, curl, and #
# gnupg, setting up the Docker repository, and installing Docker CE, #
# Docker CLI, containerd.io, docker-buildx-plugin, and docker-compose-plugin #
# packages. #
# #
# Usage: #
# - Ensure execute permissions: #
# chmod +x install_docker.sh #
# - Run the script: #
# ./install_docker.sh #
# #
# Author: Henrique Lobato #
# Date: January 4, 2024 #
# #
##############################################################################
set -e
if command -v docker &> /dev/null; then
echo "Docker is already installed. Skipping installation."
exit 0
fi
echo "Docker is not installed. Proceeding with installation..."
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
codename=$(lsb_release -cs)
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $codename stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo groupadd docker
sudo usermod -aG docker $USER
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
# docker run hello-world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment