🚀 How to Install Docker on Ubuntu: A Complete Guide for Developers
![]() |
How to Install Docker on Ubuntu In 7 steps |
Docker has revolutionized how developers build, ship, and run applications. It's an incredibly powerful tool that helps you manage application processes within isolated environments called containers. This guide will walk you through installing Docker on your Ubuntu system, making sure you're ready to dive into the world of containerization! 🐳
sudo
, which grants administrative privileges. Always be cautious when using sudo
!
1. Update Your Package List
Before installing anything new, it's a good practice to update your system's package list. This ensures you're getting the latest versions of software and dependencies. Think of it as refreshing your app store before downloading new apps! 🔄
sudo apt update
This command fetches the latest information about available packages from the repositories.
2. Install Prerequisite Packages
Next, we need to install a few essential packages that allow your system's package manager (apt
) to securely download packages over HTTPS. These are like the security keys for your software downloads. 🔑
sudo apt install apt-transport-https ca-certificates curl software-properties-common
apt-transport-https
: Enablesapt
to use repositories accessed via the HTTPS protocol.ca-certificates
: Contains commonly used CA certificates to allow secure connections.curl
: A command-line tool for transferring data with URLs, used for adding the GPG key.software-properties-common
: Provides tools for managing software repositories.
3. Add Docker's GPG Key
To ensure the Docker packages you download are authentic and haven't been tampered with, you need to add Docker's official GPG (GNU Privacy Guard) key to your system. This verifies the integrity of the downloaded packages. ✅
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
curl -fsSL ...
: Downloads the GPG key from Docker's official server.sudo apt-key add -
: Adds the downloaded GPG key to your system's list of trusted keys.
apt-key add
is being deprecated. While it still works for now, newer methods involve placing the GPG key directly in /etc/apt/trusted.gpg.d/
. For this guide, we'll stick to the common method for simplicity and broader compatibility.
4. Add the Docker Repository
Now that your system trusts Docker's GPG key, you can add the official Docker repository to your APT sources. This tells your system where to find the Docker packages. 📦
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
deb [arch=amd64]
: Specifies that we are adding a Debian-style repository for AMD64 architecture.https://download.docker.com/linux/ubuntu
: The URL of the official Docker repository for Ubuntu.focal stable
: Specifies the Ubuntu release codename (e.g., "focal" for Ubuntu 20.04 LTS) and the "stable" channel for Docker releases. Make sure to replacefocal
with your Ubuntu version's codename if you're not on 20.04 (e.g.,jammy
for 22.04,noble
for 24.04). You can find your codename by runninglsb_release -cs
.
5. Install Docker Engine
With the repository added, it's time to install Docker itself! First, update your package database again to include the newly added Docker packages. Then, we'll verify we're installing from the correct source and finally install Docker CE (Community Edition). 💪
Update Package Database (Again!)
After adding a new repository, it's crucial to update your package list so your system knows about the new Docker packages. ⬇️
sudo apt update
Verify Docker Repository (Optional but Recommended)
Before installing, it's a good idea to confirm that your system is about to install Docker from the official Docker repository and not an older version from Ubuntu's default repositories. This helps prevent unexpected issues. 🤔
apt-cache policy docker-ce
The output should show a high priority for the Docker repository (e.g., https://download.docker.com/linux/ubuntu focal/stable/docker-ce
) compared to any other sources.
Install Docker CE
Finally, install the Docker Community Edition package. This will install the Docker Engine, CLI, and containerd. 🎉
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
We're including docker-ce-cli
(the command-line interface), containerd.io
(the container runtime), and optionally docker-buildx-plugin
and docker-compose-plugin
which are incredibly useful for building multi-architecture images and managing multi-container Docker applications, respectively.
6. Verify Docker Installation
After the installation is complete, let's check if Docker is running correctly. This is like turning on a new appliance to make sure it works! ✅
sudo systemctl status docker
The output should indicate that the Docker service is active (running). You'll see something similar to this:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since ...
Docs: https://docs.docker.com
Main PID: ... (dockerd)
Tasks: ...
Memory: ...
CPU: ...
CGroup: /system.slice/docker.service
└─... /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
You can also run a simple test container to verify Docker is working: 🧪
sudo docker run hello-world
This command downloads a test image and runs it in a container. If successful, it will print a message like "Hello from Docker!" and then exit. This confirms Docker can pull images and run containers.
7. Run Docker Without Sudo (Optional but Highly Recommended)
By default, you need to use sudo
every time you run a docker
command. This can be tedious and is not always ideal for development workflows. To avoid this, you can add your user to the docker
group. This grants your user the necessary permissions to interact with the Docker daemon without needing sudo
. 🙌
Add User to Docker Group
Use the following command to add your current user to the docker
group:
sudo usermod -aG docker ${USER}
sudo usermod
: Modifies user account information.-aG docker
: Appends (-a
) your user to thedocker
group (-G docker
).${USER}
: A shell variable that represents your current username.
Apply Group Changes
For the group changes to take effect, you need to log out and log back in, or you can apply the changes in your current session by typing:
su - ${USER}
This command effectively starts a new shell session with your updated group memberships. You'll be prompted for your password.
Verify Group Membership
To confirm that your user has been successfully added to the docker
group, type:
groups
You should see docker
listed among your groups. If it is, you're all set to run Docker commands without sudo
! 🎉 Try running docker run hello-world
again without sudo
.
🎉 Conclusion
Congratulations! You've successfully installed Docker on your Ubuntu system. You're now ready to explore the vast world of containerization, build and run your applications in isolated environments, and streamline your development workflow. Docker is a game-changer, and you've taken the first important step. Happy Dockering! 🚀
❓ Frequently Asked Questions (FAQs)
sudo apt update
after adding the repository.
su - ${USER}
to start a new shell session with the updated group memberships. Simply closing and reopening the terminal might not be enough.
sudo apt update && sudo apt upgrade docker-ce docker-ce-cli containerd.io
This will upgrade Docker to the latest version available in the stable repository.
sudo apt remove docker docker-engine docker.io containerd runc