Ultimate Guide to Installing Docker on Ubuntu: Easy Bash Script Tutorial 🐳

Aleks Aleksandrov
3 min readFeb 2, 2024

Hello, tech aficionados! Ever felt like navigating the Docker installation process is akin to exploring uncharted territories? Well, fret not! Today, we’re not just going to walk you through the process; we’re going to give you a treasure map in the form of a Bash script that will effortlessly set up Docker on your Ubuntu machine. 🧙‍♂️

Before we dive into the magical realms of command lines and installations, let’s unveil the treasure map itself:

#!/bin/bash
# Ensure the script is run as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Step 1: Update package database
apt-get update
# Step 2: Install prerequisites
apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Step 3: Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
# Step 4: Add Docker's repository
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# Step 5: Install Docker
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
# Step 6: Start Docker and enable it at boot
systemctl start docker
systemctl enable docker
# Step 7: Add current user to Docker group
usermod -aG docker $USER
echo "Docker installation complete. Please log out and back in for group changes to take effect."

With this script, you’re just a few moments away from having Docker running on your system. Now, let’s break it down, step by magical step.

Step 1: The Guardian at the Gates 🚪

The journey begins with a guardian check, ensuring you have the powers of root to proceed. This step is crucial as it verifies that you have the necessary permissions to make system-wide changes.

if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi

Step 2: Gathering the Tools 🛠️

Before the main adventure begins, we need to gather our tools. This means updating our package database and installing some essential packages that will pave the way for Docker’s installation.

apt-get update
apt-get install -y apt-transport-https ca-certificates curl software-properties-common

Step 3: The Key to the Castle 🔑

Securing our installation means adding Docker’s official GPG key. This step is akin to verifying the identity of a trusted ally before allowing them into the fortress.

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

Step 4: Mapping the Realm 🗺️

With our ally’s identity confirmed, we proceed to add Docker’s repository to our system. This repository is a treasure trove of Docker packages, ready for the taking.

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Step 5: The Coronation of Docker 🐳

Now comes the moment of glory, installing Docker itself. This step brings Docker onto your system, ready to manage your containers.

apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io

Step 6: The First Voyage 🚀

With Docker installed, we ignite its engines and prepare it for the many adventures ahead, ensuring it rises automatically at every system startup.

systemctl start docker
systemctl enable docker

Step 7: Joining the Fellowship 👫

The final step in our journey is to add your user to the Docker group, granting you the power to command Docker without summoning the omnipotent sudo.

usermod -aG docker $USER

With a triumphant echo, our script concludes:

echo "Docker installation complete. Please log out and back in for group changes to take effect."

The Quest Concludes

Bravo! You’ve successfully navigated through the script and emerged victorious with Docker installed and ready at your command. Now, the world of containers is your oyster, ripe for exploration and innovation. 🌟

Remember, this journey is just the beginning. Docker opens up a realm of possibilities, from simplifying development workflows to deploying applications with ease. Use your newfound powers wisely, and may your Docker adventures lead you to uncharted successes.

Until next time, happy coding! 🚀

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Aleks Aleksandrov
Aleks Aleksandrov

Written by Aleks Aleksandrov

Junior SysOps Engineer. Passionate about Automation & Monitoring.

No responses yet

Write a response