Docker is the essential tool for containerization, allowing you to package applications and their dependencies into portable, isolated containers. This guide follows the official documentation to show you how to install the complete Docker suite (Docker Engine, CLI, and Compose plugin) on your Ubuntu Server 24.04 machine.
1. Preparation: Update Your System
Before installing any new software, it’s a best practice to update your local package index and upgrade existing packages.
-
Log in to your Ubuntu server.
-
Update and Upgrade
sudo apt update
sudo apt upgrade -y

2. Install Dependencies
You need a few packages to allow the system to use HTTPS and manage certificates when fetching the Docker repository key.
-
Install Certificates and cURL:
sudo apt install ca-certificates curl -y

3. Add the Official Docker Repository
The safest and most recommended way to install Docker is by using the official Docker repository, ensuring you get the latest stable version.
- Add Docker’s GPG Key: This step verifies the authenticity of the packages you’re about to download.
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
2.Add the Repository to Apt Sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
3. Update Apt with the New Repository:
sudo apt update

4. Install Docker Engine and Tools
With the repository configured, you can now install the main Docker packages.
-
Install Docker Components: This single command installs the core Docker Engine (
docker-ce), the command-line interface (docker-ce-cli),containerd, and the Docker Compose plugin for managing multi-container applications.
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

5. Verify Installation
Docker should start automatically after installation. You can confirm its status and test the container engine.
-
Check Service Status: Verify the Docker service is running in the background.
sudo systemctl status docker

2. Run the Test Container: Execute the simple hello-world container, which verifies that Docker can download images and run a container successfully.
sudo docker run hello-world

