
How to install Docker on Ubuntu
By Trenton Barrett on March 24, 2025 (Last updated: March 29, 2025)
Installing Docker on Ubuntu
Docker is a powerful platform for building, sharing, and running containerized applications. This guide walks you through a complete installation of Docker Engine on Ubuntu using Docker’s official repositories, including important post-installation steps to ensure everything works correctly.
Step 1: Update Your System
Begin by updating your existing list of packages. This ensures you have access to the latest versions available in your repositories.
sudo apt update
sudo apt upgrade
Step 2: Install Required Packages
Docker requires a few prerequisite packages to be installed, including support for accessing repositories over HTTPS.
sudo apt install ca-certificates curl gnupg lsb-release
Step 3: Add Docker’s Official GPG Key
Add Docker's GPG key to ensure that the packages you install are authentic and haven’t been tampered with.
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 4: Set Up the Docker Repository
Now that the GPG key is in place, add the official Docker repository to your APT sources list:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine
Update your package index with the Docker repository now included, and install Docker Engine and related components:
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Verify Docker Installation
To confirm Docker was installed successfully, run:
docker --version
You can also run the test container provided by Docker:
sudo docker run hello-world
This will download and run a simple container that prints a confirmation message, verifying the engine is functioning correctly.
Step 7: Manage Docker as a Non-root User
By default, you need to prefix Docker commands with sudo
. To avoid this and allow your user to run Docker directly:
sudo usermod -aG docker $USER
After running this command, log out and log back in for the group change to take effect. You can confirm your user is now part of the docker
group with:
groups
Try running a Docker command without sudo
to ensure everything is working:
docker run hello-world
Step 8: Enable and Start Docker on Boot
To make sure Docker runs automatically after reboot, enable the service:
sudo systemctl enable docker
sudo systemctl start docker
Step 9: Uninstall Docker (If Needed)
If at any point you need to remove Docker from your system:
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
This will completely remove Docker, containers, and all associated data.
Conclusion
You now have a fully functional Docker setup on your Ubuntu server. You can start deploying containers, explore Docker Compose for multi-container apps, or begin learning how to build your own Docker images.