Docker Install Ubuntu: A Step-by-Step Guide
To install Docker on Ubuntu, update your system, install the required packages, add Docker’s official repository and GPG key, then install the Docker Engine, CLI, and containerd, and test it with the hello-world image. The full process takes only a few minutes in the terminal. If you are asking about docker install ubuntu, the short answer is to use Docker’s official apt repository, not the older docker.io package in Ubuntu’s default repositories, because the official repository gives you the latest version and the best support.
Docker lets you run applications in isolated containers, which makes it easier to develop, test, and deploy software without worrying about differences between computers. On Ubuntu, Docker is a popular choice for developers, system administrators, and anyone learning containers. This guide walks through the official installation method step by step, explains how to run Docker without sudo, how to verify the installation, and how to fix the most common errors.
Before You Install Docker on Ubuntu
Before you start, make sure you are using a supported version of Ubuntu. Docker supports Ubuntu 22.04 LTS, Ubuntu 24.04 LTS, and other recent LTS releases on 64-bit systems. You will need a user account with sudo privileges and an internet connection. It is also a good idea to check your Ubuntu version first, so you know which repository to use. See our guide to how to check your Ubuntu version (Terminal and Settings) if you are not sure which version you are running.
You should also remove any old Docker packages that may already be installed, such as docker, docker-engine, docker.io, or containerd. These old packages can conflict with the new installation. Run the removal command, update your package list, and reboot if you are unsure whether a previous install is still active. Back up any important containers or images before you remove old packages, because they may be deleted.
Docker Install Ubuntu at a Glance
| Step | What to do | Command or action |
|---|---|---|
| 1 | Update the system | sudo apt update and sudo apt upgrade |
| 2 | Install prerequisites | ca-certificates, curl, gnupg |
| 3 | Add Docker GPG key | Download key to /etc/apt/keyrings |
| 4 | Add Docker repository | Add deb entry for your Ubuntu version |
| 5 | Install Docker | sudo apt install docker-ce docker-ce-cli containerd.io |
| 6 | Test the install | sudo docker run hello-world |
Step 1: Update Ubuntu and Install Prerequisites
Open a terminal and update your package list and installed packages. This ensures you have the latest security updates and that the Docker install will not fail because of outdated packages. Run sudo apt update, then sudo apt upgrade, and confirm when asked. This step can take a few minutes if many updates are available.
Next, install the packages Docker needs to set up its repository. These are ca-certificates, curl, and gnupg, plus software-properties-common if it is not already installed. Use the command sudo apt install ca-certificates curl gnupg. These tools let Ubuntu download Docker’s GPG key over HTTPS and verify the packages you install later. If any of these packages are already installed, apt will tell you they are up to date.
Step 2: Add Docker’s Official GPG Key and Repository
Docker signs its packages with a GPG key, and Ubuntu needs that key to trust the repository. Create the keyrings directory with sudo install -m 0755 -d /etc/apt/keyrings, then download the key with curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc, and set the permissions with sudo chmod a+r /etc/apt/keyrings/docker.asc. These commands store the key in a secure location that apt can read.
Now add the Docker repository to your apt sources. The command uses your Ubuntu codename, such as jammy for 22.04 or noble for 24.04, so it will be correct for your version. Run the command that adds deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu, followed by your codename and stable, to /etc/apt/sources.list.d/docker.list. Then run sudo apt update again so apt learns about the new repository.
Step 3: Install Docker Engine on Ubuntu
With the repository added, install Docker Engine, the Docker CLI, containerd, and the Docker Buildx and Compose plugins. The command is sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Apt will show a list of packages and ask you to confirm. Press Y and Enter, and wait for the installation to finish.
Docker will start automatically after installation on most Ubuntu systems. You can check the service with sudo systemctl status docker, which should show that the service is active and running. If it is not running, start it with sudo systemctl start docker and enable it to start on boot with sudo systemctl enable docker. This ensures Docker is ready every time you restart your computer.
Step 4: Test Docker with Hello World
Test the installation by running the hello-world image. Use the command sudo docker run hello-world. Docker will download the small hello-world image, run it in a container, and print a message that says Hello from Docker. That message confirms that Docker can pull images, create containers, and run them correctly.
If you see the hello-world message, Docker is installed and working. You can then try a larger image, such as sudo docker run -it ubuntu bash, which will download an Ubuntu image and give you a shell inside a container. Type exit to leave the container. If you want to learn more terminal basics, see our guide to how to show hidden files in Linux for other useful Linux commands.
How to Run Docker Without Sudo
By default, Docker commands need sudo, because the Docker daemon runs as root. To run Docker without sudo, add your user to the docker group with sudo usermod -aG docker $USER, then log out and log back in, or run newgrp docker in the terminal to apply the group change immediately. After that, you can run docker run hello-world without sudo.
Adding your user to the docker group is convenient, but be aware that it gives that user the ability to run containers as root, which can be a security risk on a shared system. Only add trusted users to the docker group, and do not do it on a production server unless you understand the implications. If you are the only user on your computer, it is a normal and widely used setup.
Common Docker Install Errors on Ubuntu
The most common error is permission denied when you run docker without sudo. This usually means you have not added your user to the docker group, or you have not logged out and back in yet. Try newgrp docker, or log out and log in again, and try the command with sudo to check whether Docker itself is working.
Another common error is a GPG or repository error, which can happen if the key was not downloaded correctly or if the repository line has a typo. Check that the key file exists in /etc/apt/keyrings, check the repository file in /etc/apt/sources.list.d, and run sudo apt update again to see the exact error message. If you see a 404 error, check that your Ubuntu codename is correct and that you are using a supported version.
Docker service will not start
If the Docker service will not start, check the logs with sudo journalctl -u docker.service and look for errors about storage, networking, or conflicts with an old Docker install. Remove old packages, restart the service, and check that you have enough disk space. In some cases, a reboot after installation will fix a service that failed to start the first time.
How to Update and Uninstall Docker
To update Docker, run sudo apt update and sudo apt upgrade, just as you would for any other Ubuntu package. Docker will be updated from its official repository when a new version is available. To check your Docker version, run docker –version and docker compose version.
To uninstall Docker, run sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras, then remove the images, containers, and volumes with sudo rm -rf /var/lib/docker and sudo rm -rf /var/lib/containerd. This will delete all Docker data, so back up anything important first. You can also remove the repository file and key if you do not plan to reinstall Docker.
Frequently Asked Questions
How do I install Docker on Ubuntu?
To install Docker on Ubuntu, update the system, install ca-certificates, curl, and gnupg, add Docker’s official GPG key and repository, run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin, and test with sudo docker run hello-world.
Should I use docker.io or Docker’s official repository?
Use Docker’s official repository. The docker.io package in Ubuntu’s default repositories is often older and may not have the latest features or security fixes. The official repository gives you the current Docker Engine and is the method Docker recommends.
Do I need sudo to run Docker?
You need sudo by default, but you can add your user to the docker group with sudo usermod -aG docker $USER and then log out and log back in. After that, you can run docker commands without sudo. Only add trusted users to the docker group.
How do I check if Docker is installed correctly?
Run sudo docker run hello-world. If Docker prints Hello from Docker, the installation is working. You can also run docker –version to check the version and sudo systemctl status docker to check that the service is running.
Can I install Docker on Ubuntu 22.04 and 24.04?
Yes, Docker supports both Ubuntu 22.04 LTS and Ubuntu 24.04 LTS, as well as other recent LTS releases. The installation steps are the same, but the repository codename will be different, so make sure the repository command uses the codename for your version.
Conclusion
Docker install ubuntu is straightforward when you use Docker’s official repository. Update Ubuntu, install the prerequisites, add the GPG key and repository, install docker-ce and its plugins, and test with hello-world. Add your user to the docker group if you want to run Docker without sudo, and keep Docker updated with apt. With Docker installed, you can start running containers, building images, and using Docker Compose to manage multi-container applications on Ubuntu.