How to Install Docker in Ubuntu
Key Takeaways
- Official Repository is Best: Always install Docker Engine from Docker’s official
aptrepository to ensure you receive the latest, most secure version. - Process Overview: The installation involves updating your system, adding Docker’s GPG key for security, adding the official repository, and then installing the Docker packages.
- Post-Installation Steps: After installation, add your user to the
dockergroup to run commands withoutsudoand verify the installation by running thehello-worldcontainer. - Complete Package: The installation includes Docker Engine, the Docker CLI,
containerd, and plugins for Docker Buildx and Docker Compose, providing a full container management toolkit.
How Do You Install Docker on Ubuntu?
To install Docker on Ubuntu, you must add Docker’s official APT repository, install the required packages, configure user permissions, and verify the installation with a test container. Below is the complete, secure, and recommended installation method.
Step 1: Why Should You Prepare Your System for Installation?
Before adding new software, it’s a best practice to prepare your system. This involves updating your local package index to ensure you have the latest information about available software and installing a few essential packages that allow the apt package manager to manage repositories over a secure HTTPS connection.
- First, open your terminal and refresh your package list:
sudo apt-get update- Next, install the necessary prerequisite packages:
sudo apt-get install ca-certificates curl gnupgStep 2: How Do You Add Docker’s Official GPG Key?
A GPG (GNU Privacy Guard) key is used to sign software packages, and adding Docker’s key allows your system to verify that the Docker packages you download are authentic and have not been tampered with. This is a critical security step.
- Create a dedicated directory for GPG keys:
sudo install -m 0755 -d /etc/apt/keyrings- Download Docker’s official GPG key and save it in the new directory:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg- Modify the key’s permissions to make it readable by all users:
sudo chmod a+r /etc/apt/keyrings/docker.gpgStep 3: How Do You Set Up the Docker Repository?
With the GPG key in place, you can now safely add the official Docker repository to your system’s sources. This tells the apt package manager where to find the Docker Engine installation files. The following command automatically detects your Ubuntu version and sets up the correct repository.
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullStep 4: What Packages Do You Need to Install?
Now that your system is configured to use the Docker repository, you can proceed with the installation. You’ll update your package list one more time to include the packages from the newly added Docker repo and then install Docker Engine itself.
- Update the package list again to include the Docker packages:
sudo apt-get update- Install Docker Engine, CLI,
containerd, and the Buildx and Compose plugins:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginThis command installs everything you need for a modern Docker workflow. If you want to dive deeper into managing multi-container applications, check out our [beginner’s guide to Docker Compose].
Step 5: How Can You Run Docker Without sudo?
By default, the Docker daemon binds to a Unix socket owned by the root user. To avoid having to type sudo for every command, you should add your user to the docker group, which is created during installation. This grants your user the necessary permissions.
- Add your current user to the
dockergroup:
sudo usermod -aG docker $USER- Important: For this change to take effect, you must log out of your current session and log back in, or restart your system.
Step 6: How Do You Verify the Installation is Working?
The final step is to confirm that Docker Engine is installed and running correctly. The standard way to do this is by running the lightweight hello-world container. This image is designed specifically to test Docker installations.
Run the following command in your terminal:
docker run hello-worldIf your installation is successful, Docker will download the image and run the container. You will see a confirmation message in your terminal that begins with “Hello from Docker!” This confirms that your setup is complete and ready for you to start building and running containers.

What Are the Next Steps After Installing Docker?
Congratulations, you have a fully functional Docker environment! Your journey is just beginning. You can now explore pulling more complex application images from Docker Hub, such as a web server, or start writing your own Dockerfiles to containerize your applications.
For example, try running an NGINX web server with a single command:
docker run --name some-nginx -p 8080:80 -d nginxYou can now visit http://localhost:8080 in your browser and see the NGINX welcome page.
How Do You Keep Docker Engine Updated on Ubuntu?
Short Answer: Use APT — Docker’s repo ensures updates arrive automatically.
Update Docker packages:
sudo apt-get update
sudo apt-get upgrade docker-ce docker-ce-cli containerd.io
You can also check the installed version:
docker versionKeeping Docker updated ensures you always have the latest features and security patches.
Common Issues & How to Fix Them
Docker command not found?
Run:
which docker
Permission denied when running docker?
You likely forgot to re-login after joining the docker group. Restart your session.
hello-world image fails to download?
Check your network or corporate proxy settings.

Recent Comments