How to Install Docker in Ubuntu: Step-by-Step Guide | OpsNexa

In today’s dynamic world of cloud computing, DevOps, and containerized applications, Docker has become a must-have tool for developers and IT teams.
At OpsNexa, we know that faster deployments and streamlined development pipelines start with mastering essential tools — and Docker is at the top of that list.

If you’re running Ubuntu — one of the most popular Linux distributions — installing Docker is straightforward, but it’s important to do it the right way for security, stability, and future upgrades.

Here’s your comprehensive guide on how to install Docker in Ubuntu — the OpsNexa way: fast, clean, and future-ready.


What is Docker?

Docker is an open-source platform that allows developers to automate the deployment of applications inside lightweight, portable containers.
Containers bundle your app’s code, libraries, and dependencies into a single package, ensuring it works seamlessly across different environments.

✅ Consistency across dev, test, and prod
✅ Simplified deployment
✅ Increased scalability

At OpsNexa, we treat Docker as the backbone of modern app infrastructure.


Prerequisites Before You Begin

Before installing Docker on Ubuntu, make sure:

  • You have an Ubuntu server or desktop running (Ubuntu 22.04, 20.04, or 18.04 LTS recommended).

  • You have a user account with sudo privileges.

  • Your system is updated.

Update your system first:

bash
sudo apt update
sudo apt upgrade -y

✅ This ensures you’re working with the latest packages and security patches.


How to Install Docker in Ubuntu: Step-by-Step

Ready? Let’s dive in.


Step 1: Uninstall Old Versions (If Any)

If you previously installed Docker, it might be under older names like docker, docker-engine, or docker.io.

Run:

bash
sudo apt remove docker docker-engine docker.io containerd runc

This clears the way for a clean installation.


Step 2: Set Up the Repository

To install the latest version of Docker, you should set up Docker’s official repository.

First, install packages to allow apt to use a repository over HTTPS:

bash
sudo apt install apt-transport-https ca-certificates curl software-properties-common lsb-release -y

Then, add Docker’s official GPG key:

bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Next, add the stable Docker repository:

bash
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

✅ Now your system knows where to get the latest and greatest Docker builds.


Step 3: Install Docker Engine

First, update the package database again:

bash
sudo apt update

Now install Docker:

bash
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Let the installer do its magic. ✨


Step 4: Verify the Docker Installation

Check that Docker is installed correctly by running:

bash
sudo docker --version

You should see output similar to:

plaintext
Docker version 24.0.2, build cb74dfc

Awesome — you’ve officially installed Docker! 🚀


Step 5: Manage Docker as a Non-Root User (Optional, but Recommended)

By default, you’ll need sudo every time you run Docker commands.
If you want to avoid that, add your user to the docker group:

bash
sudo usermod -aG docker $USER

Then log out and back in, or type:

bash
newgrp docker

Now you can run Docker without typing sudo every time. 💪

Example:

bash
docker run hello-world

This will download and run a test container to confirm everything’s working.


Optional: Install Docker Compose (If Needed)

Docker Compose is a tool that lets you define and manage multi-container Docker applications.

If you installed the docker-compose-plugin above, you’re good.
Otherwise, you can manually install Docker Compose:

bash
sudo apt install docker-compose -y

Check the installation:

bash
docker compose version

✅ Now you’re ready to orchestrate entire microservices systems!


Quick Troubleshooting Tips

🔧 Docker Daemon Not Running?

Start it manually:

bash
sudo systemctl start docker

Enable it on boot:

bash
sudo systemctl enable docker

🔧 Permission Issues After Adding User to Docker Group?

Remember: you must log out and log back in for group changes to apply.


Why Install Docker from the Official Repository?

You might wonder:

“Why not just sudo apt install docker.io and call it a day?”

Good question.

While Ubuntu’s default repositories contain Docker, they might lag behind the official Docker releases.
Using Docker’s own repository ensures you get:

✅ The latest features
✅ Security patches
✅ Better support for plugins and extensions
✅ Stability improvements

At OpsNexa, we always recommend direct, secure, and future-ready installations.


Bonus: Docker Commands Cheat Sheet

Here’s a quick look at Docker basics once you’re installed:

Command What It Does
docker run hello-world Run a test container
docker ps List running containers
docker ps -a List all containers (including stopped ones)
docker images List downloaded Docker images
docker pull <image> Download a Docker image
docker stop <container> Stop a running container
docker rm <container> Remove a container
docker rmi <image> Remove a Docker image

Bookmark this — you’ll use them often!


Final Thoughts: Ready to Level Up with Docker

Installing Docker on Ubuntu isn’t just a technical milestone — it’s a gateway to faster development, easier deployments, and smarter workflows.

At OpsNexa, we believe every modern business can benefit from adopting container-first mindsets — whether you’re scaling microservices, building cloud-native apps, or just improving your local dev environments.

Empower your systems. Empower your future.

Now that you’ve installed Docker, the real journey begins.
Stay tuned — we’ve got tons of next-level Docker guides coming up!