Installing Docker from the Official Script on Debian/Ubuntu
This guide walks you through installing the latest stable version of Docker Engine using the official convenience script provided by Docker, and then adding your user to the docker group so you can run Docker commands without sudo.
Warning
The official convenience script is designed for testing and development environments. It installs dependencies, adds Docker’s GPG key and repository, configures the Docker daemon, and starts the service. Review the script before running it. For production systems, use the repository-based installation method instead.
Prerequisites
- A Debian- or Ubuntu-based distribution (e.g., Ubuntu 20.04+, Debian 11+).
- A user account with
sudoprivileges. - Internet access.
Step 1 – Download and Run the Docker Installation Script
-
Open a terminal.
-
Download the script using
curlorwget:bashcurl -fsSL https://get.docker.com -o get-docker.shor
bashwget -qO get-docker.sh https://get.docker.com -
(Optional) Review the script contents:
bashless get-docker.sh -
Run the script with
sudo:bashsudo sh get-docker.shThe script will:
- Detect your distribution and version.
- Add Docker’s official APT repository.
- Install Docker Engine, CLI, containerd, and Docker Compose (v2 plugin).
- Start and enable the Docker service.
-
Once the script finishes, verify that Docker is installed and running:
bashsudo docker version sudo docker infoThese commands should display version information and system details.
Step 2 – Add Your User to the Docker Group
By default, docker commands require sudo. To allow your user to run Docker without sudo, add your user to the docker group.
-
Add your user to the
dockergroup:bashsudo usermod -aG docker $USERReplace
$USERwith your actual username if needed;$USERautomatically expands to your current username. -
Apply the group change. You must log out and back in for the change to take effect. Alternatively, use one of the following methods to avoid logging out:
-
Method A – Start a new shell session with the group already applied (temporary):
bashnewgrp docker -
Method B – Run
su - $USERto start a fresh login session.
Note: If you are using a desktop environment, the simplest way is to log out and log back in.
-
-
Verify that you can run Docker commands without
sudo:bashdocker run hello-worldIf everything is set up correctly, you will see a welcome message from Docker.
Step 3 – (Optional) Manage Docker as a Non-Root User
After adding your user to the docker group, you can run all docker commands without sudo. However, be aware of the security implications: users in the docker group have effective root access. Only add trusted users to this group.
To check which users belong to the docker group:
getent group docker
Step 4 – Clean Up (Optional)
The downloaded script file can be removed:
rm get-docker.sh
Troubleshooting
-
“Permission denied” when running
dockercommands – Ensure your user is in thedockergroup and you have started a new session after the group modification. -
Script fails with “unsupported distribution” – The official script only supports certain versions of Debian and Ubuntu. Check Docker’s documentation for supported distributions.
-
Docker service not running – Start it manually:
bashsudo systemctl start docker sudo systemctl enable docker
Uninstalling Docker
If you ever need to remove Docker installed via the script, see the official uninstallation guide for Debian/Ubuntu.
apt-get update
apt-get install -y curl
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
usermod -aG docker root
Proven
Summary
- Use
curl -fsSL https://get.docker.com | sudo shto install Docker from the official script. - Add your user to the
dockergroup withsudo usermod -aG docker $USER. - Log out and back in (or use
newgrp docker) to apply group membership. - Verify with
docker run hello-world.
This method gives you a quick Docker setup on Debian/Ubuntu. For production environments, consider the repository-based installation to have more control over updates and dependencies.