How to Install Docker on Ubuntu: A Step-by-Step Guide for Beginners
Master the fundamentals of containerization by following this comprehensive, step-by-step guide to installing and configuring Docker Engine on Ubuntu. Learn how to securely set up official repositories, streamline your workflow by running Docker without sudo privileges, and verify your installation using a test container. Get your development or production environment ready to build, ship, and run scalable applications with confidence.
Containerization has completely revolutionized how developers build, ship, and run applications. Among the various tools available today, Docker stands out as the undisputed industry standard. By packaging an application and its dependencies into a single lightweight container, Docker ensures that your software runs seamlessly, regardless of the underlying infrastructure.
If you are developing on Linux, Ubuntu is one of the most popular and stable platforms for running containerized workloads. Whether you are setting up a local development environment or preparing a production-ready cloud server, getting Docker up and running on Ubuntu is a fundamental skill every developer should master.
In this comprehensive guide, we will walk you through the step-by-step process of installing Docker Engine on Ubuntu, configuring it for optimal usage, and verifying your installation with a test container.
Step 1: Preparing Your Ubuntu System
Before installing any new software, it is always a best practice to update your local package index to ensure you are working with the latest repository information. Open your terminal and run the following commands to update your system's package list and upgrade existing packages:
sudo apt update
sudo apt upgrade -y
Next, you need to install a few prerequisite packages that allow apt to use packages over HTTPS. These tools are essential for securely downloading and adding Docker's official GPG key:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg -y
With your system updated and prerequisites installed, you are now ready to move on to adding Docker's official repositories.
Step 2: Adding the Official Docker Repository
While Ubuntu’s default repositories sometimes contain older versions of Docker, it is always recommended to install the official Docker Engine to get the latest features, performance improvements, and security patches.
First, add Docker’s official GPG key to ensure the authenticity of the software you are downloading:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Next, set up the stable Docker repository by running the following command. This command dynamically detects your Ubuntu version codename (such as jammy or focal) and configures the repository accordingly:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now that the repository has been successfully added, update your local package index once more so apt recognizes the new Docker packages:
sudo apt update
Step 3: Installing Docker Engine
With the repository configured, you are ready to install Docker Engine along with the Docker CLI and container runtime components. Run the following command in your terminal:
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
This command installs several crucial components:
- docker-ce: The Docker Community Edition daemon (the core engine).
- docker-ce-cli: The command-line interface used to interact with Docker.
- containerd.io: The container runtime that manages the complete lifecycle of containers.
- docker-buildx-plugin: Extends Docker with advanced multi-architecture build capabilities.
- docker-compose-plugin: The latest version of Docker Compose, allowing you to run multi-container applications easily.
Once the installation finishes, the Docker service should start automatically. You can verify that the Docker daemon is active and running by typing:
sudo systemctl status docker
Step 4: Executing Docker Without Sudo (Optional but Recommended)
By default, running the docker command requires root privileges, meaning you must prefix your commands with sudo. If you prefer to run Docker commands as a standard user without typing sudo every time, you can add your user account to the docker security group.
Create the docker group if it does not already exist and add your current user to it:
sudo usermod -aG docker $USER
To apply these new group memberships, log out of your system and log back in, or run the following command to refresh your current terminal session immediately:
newgrp docker
Step 5: Verifying the Installation
Now comes the exciting part: testing whether your Docker installation works correctly! Docker provides a lightweight hello-world image specifically designed for this purpose.
Run the following command to download and execute the test container:
docker run hello-world
If your installation was successful, Docker will download the hello-world image, create a container, run it, and print an informational message confirming that the installation is working correctly. This verifies that both the daemon and CLI are communicating properly.
Conclusion
Congratulations! You have successfully installed Docker Engine and Docker Compose on your Ubuntu system. You are now fully equipped to build, test, and deploy containerized applications with confidence.
Containerization simplifies dependency management, scales effortlessly, and ensures consistency across different development and production environments. As you continue your Docker journey, consider exploring advanced topics such as writing multi-stage Dockerfiles, orchestrating containers with Kubernetes, or managing persistent volumes for your databases.
More in Technology
How to Fix MySQL Bottlenecks on a VPS: Speed Up WordPress and Lower CPU Usage
Tired of sudden CPU spikes and database connection errors on your WordPress VPS? Learn how to diagnose slow queries, optimize your memory allocation, and audit resource-heavy plugins to dramatically accelerate your site's performance.
Zero-Trust API Security: Why Web Hosts Are Revoking Wide-Scope Tokens
For years, the reliance on wide-scope, permanent API tokens has created a massive cybersecurity blind spot in web hosting and cloud environments. To combat rising supply-chain attacks, providers are now aggressively auditing, restricting, and revoking these legacy "master keys." Organizations must quickly adapt by embracing Zero-Trust principles, enforcing the principle of least privilege, and adopting short-lived, granular credentials to prevent imminent downtime and breaches.
Automated DDoS Mitigation: How Cloud Infrastructure Stops Attacks Before They Hit Your Server
Discover how modern automated DDoS mitigation leverages cloud infrastructure and edge intelligence to protect critical web applications from increasingly sophisticated cyber threats. By shifting defense mechanisms to the network edge, organizations can neutralize volumetric and application-layer attacks in milliseconds without relying on slow manual intervention.