News & Updates

How to Install Docker on Ubuntu: Step-by-Step Guide

By Marcus Reyes 16 Views
how to install docker ubuntu
How to Install Docker on Ubuntu: Step-by-Step Guide

Setting up Docker on Ubuntu is a foundational skill for modern developers and system administrators. This containerization platform allows you to package applications and dependencies into isolated, portable units that run consistently across different environments. The process on Ubuntu is streamlined thanks to the official repository and well-maintained packages.

Updating Your System

Before installing any new software, it is best practice to ensure your local package index is up to date. This step synchronizes your package list with the latest available versions from the Ubuntu repositories. Running this command also prepares the system for a clean installation by resolving any potential conflicts.

Refreshing Package Lists

Open your terminal and execute the update command to refresh the local package index. This operation fetches the latest metadata but does not install or upgrade any packages yet.

sudo apt update

Installing Required Dependencies

To add the Docker repository to your system, you need a package that allows secure HTTPS transmission. This utility package ensures that the connection to Docker’s official repository is encrypted and authenticated. Installing it beforehand guarantees that the subsequent repository configuration will succeed without errors.

Adding HTTPS Support

Install the necessary packages to allow the system to access repositories over HTTPS using the following command.

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

Adding the Docker GPG Key and Repository

Security is paramount when adding third-party repositories. The Docker maintainers provide a GPG key that verifies the authenticity of the packages. Adding this key ensures that the packages you install are genuine and have not been tampered with during transmission.

Configuring the Key and Stable Repository

First, add the Docker official GPG key to your system’s trusted keychain. Then, add the Docker APT repository to your sources list to receive stable releases.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) 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

Installing the Docker Engine

With the repository configured, you can now install the Docker Engine package. This is the core component that manages the containers, images, networks, and storage volumes. The installation process will also set up the necessary systemd service to manage Docker as a background daemon.

Running the Installation Command

Update your package list one last time to include the Docker packages from the new repository, then install the docker-ce package.

sudo apt update

sudo apt install docker-ce docker-ce-cli containerd.io -y

Verifying the Installation

Once the installation completes, the Docker daemon should start automatically. You can check its operational status to confirm that everything is running smoothly. This verification step ensures that the service is active and enabled for future reboots.

Checking Service Status

Use the systemctl command to verify that Docker is active and running without errors.

sudo systemctl status docker

Running the Docker Command Without Sudo

M

Written by Marcus Reyes

Marcus Reyes is a Senior Editor with 15 years of experience investigating complex global narratives. He brings razor-sharp analysis and unapologetic perspective to every story.