Installing Docker on Ubuntu from the Official Repository
A step-by-step guide to installing Docker from the official apt repository, as documented on docs.docker.com, including running it without sudo and a final test.

Table of contents
In this guide we install Docker on Ubuntu from the official apt repository, which is the method Docker’s own documentation recommends. Avoid the distribution’s docker.io package; it usually lags well behind the current release.
Step 0: remove older installs
If you have old or unofficial packages installed, remove them first (it is fine if none of them are present):
sudo apt-get remove docker docker-engine docker.io containerd runc
Step 1: add the key and the official repository
sudo apt-get update
sudo apt-get install ca-certificates curl
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
Now add the repository itself:
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
Step 2: install
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
The docker-compose-plugin package provides the docker compose command (Compose v2, no hyphen).
Step 3: run Docker without sudo
To let your current user run Docker without sudo, add it to the docker group, then log out and back in once:
sudo usermod -aG docker $USER
Keep in mind that membership of the docker group is effectively root access on that machine, so only add users you would trust with root.
Step 4: test
docker run hello-world
If you see “Hello from Docker!”, everything works. If your server is in Iran and image pulls are slow or fail, read our guide to setting up the ArvanCloud registry mirror.
Versions and updates
Check what you installed with docker --version and docker compose version. Because Docker now comes from an apt repository, security updates arrive through the usual apt upgrade along with everything else.



Comments
No comments yet. For technical questions, include the details (OS version, the exact error and the command you ran) to get a precise answer.