Install Docker on Ubuntu
Docker Engine is installed on Ubuntu by adding Docker's official apt repository and installing the docker-ce packages.
- Updated Nov 27, 2026
- Markdown
Install Docker Engine from Docker's apt repository and run the hello-world test.
- An Ubuntu server you can reach over SSH
- A user with sudo rights
To install Docker on Ubuntu, add Docker’s apt repository and install the docker-ce packages. A fresh Ubuntu server cannot run containers until Docker Engine is installed. The install is not one command, because Ubuntu’s own docker.io package can lag behind, so Docker publishes its own apt repository. You add that repository once, and after that apt installs and updates Docker like any other package.
How it works#
Docker Engine is a background service (dockerd) with a command line client (docker) that talks to it. The two communicate through a Unix socket at /var/run/docker.sock. Whoever can write to that socket can tell the daemon to do anything, including mounting the host’s filesystem into a container. That is why access to the socket is effectively root access.
The install has three parts:
- A signing key. You download Docker’s public key so apt can verify that packages really come from Docker.
- A repository entry. A line in
/etc/apt/sources.list.d/docker.listtells apt where to find packages. It uses your CPU architecture and your Ubuntu release codename, such as the name printed bylsb_release -cs. - The packages.
docker-ceis the engine,docker-ce-clithe client,containerd.iothe runtime underneath, and the buildx and compose plugins adddocker buildxanddocker compose.
After installing, the service is enabled and starts at boot. Only root and members of the docker group can use the socket.
These steps follow Docker’s official guide for Ubuntu. Check the source link at the bottom if your Ubuntu version is new.
Step 1: Remove old packages#
sudo apt remove docker.io docker-doc docker-compose podman-docker containerd runcWhat you should see: apt lists packages to remove, or says they are not installed. If none are installed, it continues without error. This removes packages only. Images, containers and volumes under /var/lib/docker are kept.
Step 2: Add Docker’s repository#
sudo apt update
sudo apt 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
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt updateWhat the key parts do: curl -fsSL downloads quietly, follows redirects and fails on HTTP errors. The echo line builds the repository entry from your architecture and release name and writes it with tee. What you should see: the final apt update lists lines for download.docker.com with no errors.
Step 3: Install Docker Engine#
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginWhat you should see: apt unpacks the packages and starts the service. Confirm with sudo systemctl status docker, which should say active (running). Press q to leave the status view.
Step 4: Run the test container#
sudo docker run hello-worldWhat you should see: Docker says it cannot find the image locally, pulls hello-world, and prints a message that starts with “Hello from Docker!”. That means the engine pulled an image and ran a container.
Step 5: Run Docker without sudo (optional)#
Members of the group have root-level power (see Linux file permissions explained for how groups work).
sudo usermod -aG docker $USER-aG appends your user to the docker group without removing other groups. Group changes apply to new login sessions, so log out and back in, then run docker run hello-world without sudo. For a quick test in the current terminal, newgrp docker starts a shell with the group active.
Check it worked#
docker --version
docker compose version
docker run --rm hello-worldYou should see a version line starting with Docker version, a line starting with Docker Compose version, and the “Hello from Docker!” message. The --rm flag removes the finished test container so it does not pile up. If the last command fails with a permission error, use sudo or finish step 5 and log in again.
Edge cases and gotchas#
- Docker bypasses ufw for published ports. Docker writes its own iptables rules, so a container started with
-p 8080:80can be reachable from the internet even if ufw has no rule for 8080. Bind to127.0.0.1(for example-p 127.0.0.1:8080:80) when a port should stay private. - The docker group is root in disguise. Anyone in it can start a container that mounts
/and change any file. Add only people you would give root to. - New Ubuntu releases can lag. The repository line uses your release codename. If Docker has not published packages for it yet,
apt updateshows a 404 for that repository. Use an LTS release, or follow Docker’s current instructions for your version. - ARM servers need ARM images. The packages install fine on arm64, but an image built only for amd64 fails with
exec format error. Look for multi-architecture images. - Snap or other installs can conflict. If Docker came from a snap or another source, remove it first. Two daemons fight over the socket and the data directory.
- Docker needs disk space. Images and layers live under
/var/lib/docker. A small root disk can fill up, so checkdf -hand see Free disk space with Docker prune safely. - Group changes need a new login. After
usermod, existing terminals keep the old groups, so a permission error right after step 5 is expected.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? | The service is not running | sudo systemctl start docker, then check systemctl status docker |
permission denied while trying to connect to the Docker daemon socket | Your user is not in the docker group, or you did not log in again | Finish step 5, log out and in, or use sudo |
E: Unable to locate package docker-ce | The repository was not added, or apt update was skipped | Redo step 2 and run sudo apt update |
404 Not Found for download.docker.com | Docker has no packages for your release codename yet | Use a supported Ubuntu LTS, or check Docker’s install guide |
NO_PUBKEY or a signature warning | The key file is missing or unreadable | Redo the curl and chmod a+r lines in step 2 |
exec format error when running an image | The image does not match your CPU architecture | Choose an image published for your architecture |
Got permission denied after adding the group | The shell has the old group list | Log out and back in, or run newgrp docker |
docker: command not found after install | The shell has not picked up the path, or the install failed | Open a new shell and run which docker |
docker compose says unknown command | The compose plugin is missing | Install docker-compose-plugin from step 3 |
apt reports a conflict with containerd | An older containerd package is installed | Remove it as in step 1, then install again |
Real-world scenario#
You rent a new Ubuntu server and want to run a web app in a container. You log in, run the removal command from step 1 (nothing is installed), add the repository and install the five packages.
sudo docker run hello-world prints the greeting. You add your user to the docker group, log out and in, and docker run --rm hello-world now works without sudo.
You then start an app with -p 8080:80 and find it open on the public address even though ufw has no rule for 8080. That is Docker writing its own iptables rules. From then on you bind private ports to 127.0.0.1.
Quick reference#
| Task | Command |
|---|---|
| Remove old packages | sudo apt remove docker.io docker-doc docker-compose podman-docker containerd runc |
| Install | sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin |
| Test | sudo docker run hello-world |
| No sudo | sudo usermod -aG docker $USER |
| Status | sudo systemctl status docker |
| Versions | docker --version and docker compose version |
Security and safety notes#
- Treat the
dockergroup like root access. - Published container ports can bypass ufw, so check what is exposed with
sudo ss -tlnp.
Related lessons#
- Run your first container: the next hands-on step
- Docker Compose basics: run several containers together
- Publish container ports safely: the ufw bypass in detail
- Set up a firewall with ufw: protect the host as well
- Free disk space with Docker prune safely: when images fill the disk
Next#
Start something real with Run your first container.
Try it: Install Docker on Ubuntu
Refresh apt, install the packages and run the hello-world test.
Want a real machine? Free browser labs: Killercoda Play with Docker
Check what you learned
Frequently asked questions
Should I install Docker with apt install docker.io?
That package is maintained by Ubuntu and can lag behind. Docker's own repository gives current releases, so the official guide recommends it.
Is it safe to add my user to the docker group?
Members of the docker group have root-level power on the machine. Do it only for users you trust, or use sudo instead.
Does Docker work on a server with an ARM processor?
Yes. The repository line uses your architecture (amd64, arm64 and others are published). The catch is that an image must also exist for that architecture, otherwise it fails with an exec format error.
Will removing the old packages delete my containers and images?
No. The remove command in step 1 removes packages, not the data under /var/lib/docker, so existing images and volumes stay in place.
Sources
Keep going: guides and tutorials
- Deploy a Docker Compose App Self-Hosted: Web, Redis and Rollback Deploy a Docker Compose app on your own server with Levelrail: a web service and Redis, a bad release that does not take traffic, and a compose rollback.
- Docker Container Restarting in a Loop: 5 Causes, Fixed Five real reasons a Docker container keeps restarting, each reproduced with its exit code, the command that finds it and the fix. Then the same crash on Levelrail.
- Deploy an Express App to a VPS With Docker and Health Checks Deploy a Node.js Express API to your own server with no Dockerfile. Covers the port rule, a health route, secrets, deploy failure codes and rollback.