How to Install Docker Engine on Ubuntu and Debian Fast
Install Docker Engine on Ubuntu or Debian from Docker's own apt repository, verify it with hello world and avoid the old docker.io package conflict.

There are three ways to get Docker on Ubuntu or Debian: the distribution's docker.io package, Docker's convenience script, and Docker's own apt repository. The last is the one to use on any machine you intend to keep updated, and it is five short steps. Afterward you will want to run Docker without typing sudo, which has its own trade-off; see running Docker without sudo. Using the engine comes next in the Docker tutorial for beginners, and the whole subject sits under shell scripting inside Docker containers.
The steps follow Docker's published instructions for Docker Engine 28 on Ubuntu 24.04 and Debian 13. For Debian, replace ubuntu with debian in the URLs.
Step 1: remove conflicting packages
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do
sudo apt-get remove -y "$pkg"
doneThis does not delete images or containers under /var/lib/docker; it only removes unofficial packages that would collide with the official ones. If none are installed, apt reports it and moves on.
Step 2: add Docker's key and repository
sudo apt-get update
sudo apt-get install -y 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.ascsudo tee /etc/apt/sources.list.d/docker.sources >/dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt-get updateThe key file lets apt verify packages come from Docker, and Signed-By limits that trust to this one repository, which is the modern replacement for adding keys to a global keyring. The subshell fills in the release codename, such as noble. Derivatives like Linux Mint report their own codename in VERSION_CODENAME, which is why the line prefers UBUNTU_CODENAME.
Step 3: install
sudo apt-get install -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-pluginThe service starts automatically on Debian and Ubuntu. Check it with systemctl status docker.
Step 4: verify
sudo docker run --rm hello-world
sudo docker version
sudo docker compose versionThe first command pulls a tiny image and prints a message beginning Hello from Docker!, which proves the daemon, the registry connection and the container runtime all work. If it hangs on the pull, the cause is usually a proxy or DNS.
Updating and pinning
Docker's packages update with the rest of the system through apt upgrade. A package upgrade restarts the daemon and, unless live restore is configured, stops running containers. On production hosts, hold the packages (sudo apt-mark hold docker-ce) and upgrade in a window. To install a specific version, list them with apt-cache madison docker-ce and pass docker-ce=VERSION.
The convenience script
curl -fsSL https://get.docker.com | sh detects the distribution and runs the steps above. Docker documents it as meant for development and test environments, since it installs without letting you review the repository first, and you should read a script before you pipe it into a shell. The repository method gives a system whose updates you can reason about.
What the repository setup does
The packages in Debian's and Ubuntu's own repositories are older builds with different names, such as docker.io. Docker's project publishes current packages in its own apt repository, signed with a key you add to the system. The setup does three things: it fetches that signing key into /etc/apt/keyrings, it writes a sources file naming the repository and the key, and it refreshes the package index. From then on apt treats docker-ce like any other package, and upgrades come with apt upgrade.
The key location matters. A key placed in the old global keyring trusts the repository for every package on the system, and a key referenced with Signed-By in the sources file trusts it only for that repository. Use the second form, as the steps above do. Check that the sources file points to the right distribution codename with cat /etc/apt/sources.list.d/docker.sources, and check what apt would install without installing it.
apt-cache policy docker-ce | head -n 5The first lines show the installed version, the candidate version and the repository it comes from. If the candidate says it comes from a Debian or Ubuntu mirror instead of download.docker.com, the sources file is not being read, and the usual cause is a codename the repository does not carry yet.
Verify more than the hello-world image
The hello-world run proves that the client reached the daemon and the daemon pulled an image. Four more checks catch the problems that appear later. docker info shows the storage driver, which should be overlayfs or overlay2 on a modern kernel. systemctl is-enabled docker confirms the daemon starts at boot. docker compose version confirms the Compose plugin came with the packages. And docker run --rm alpine:3.22 wget -qO- https://example.com | head -n 3 proves that containers can reach the network, which a firewall configured with ufw or iptables sometimes blocks, because Docker manages its own rules and a restrictive host firewall can interfere.
docker info --format '{{.Driver}} {{.CgroupVersion}} {{.ServerVersion}}'
systemctl is-enabled dockerPinning and holding versions
Upgrading Docker restarts the daemon, and containers stop with it unless live restore is enabled. On a production host, schedule upgrades, and consider setting "live-restore": true in /etc/docker/daemon.json so running containers survive a daemon restart. To stop an unplanned upgrade, hold the packages with sudo apt-mark hold docker-ce docker-ce-cli containerd.io, and release the hold when you are ready to test. Install a specific version by listing the available ones with apt-cache madison docker-ce and passing the full version string. Keeping the client and the server on matching major versions avoids API negotiation surprises, since the client falls back to an older API version and some features disappear without an error.
Keeping the installation healthy
After the install, set up three things. Make the daemon start at boot, with sudo systemctl enable docker. Configure log rotation for containers, since the default JSON log driver keeps logs without limit, and a chatty container will fill the disk. In /etc/docker/daemon.json set "log-driver": "local", or keep json-file with "log-opts": {"max-size": "10m", "max-file": "3"}, then restart the daemon. And schedule cleanup of unused images, because every pull and build leaves layers behind: docker system df shows the usage and docker image prune -a --filter "until=720h" removes images that have not been used for thirty days. Check the disk use every few months until you know your pattern.
docker system df
sudo du -sh /var/lib/dockerKnow where the data lives. Images, containers and volumes sit under /var/lib/docker, which can grow to tens of gigabytes. If your root partition is small, move that directory to a larger disk by setting "data-root" in the daemon configuration, stopping Docker, copying the directory with rsync -a and starting it again. Do it before the disk is full, and not while the daemon is failing, because a full disk makes the daemon fail to start.
When this does not apply
Fedora and RHEL use a different repository; Alpine has apk add docker; and on macOS and Windows you use Docker Desktop or an alternative such as Colima. Rootless mode and Podman avoid running a root daemon at all, which suits some security models. The authoritative steps are in Docker's Ubuntu instructions and the Debian page.


