Home » How to Install Docker on Ubuntu
Posted in

How to Install Docker on Ubuntu

If you’re diving into the world of containers, there’s a good chance Docker is at the top of your list. It’s lightweight, fast, and widely used for deploying applications in isolated environments.

Whether you’re setting up a development environment, experimenting with microservices, or launching production containers, Docker makes it easy. In this guide, we’ll walk through:

✅ Installing Docker on Ubuntu
✅ Running Docker without needing sudo
✅ Testing your setup with a simple container

Let’s get started!


🚀 Step 1: Update Your System

First, make sure everything on your system is up-to-date:

sudo apt update && sudo apt upgrade -y

🐳 Step 2: Install Docker on Ubuntu

1. Uninstall old Docker versions (if any):

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

2. Install required packages:

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

3. Add Docker’s official GPG key:

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

4. Add the Docker repository:

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

5. Install Docker:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y

✅ Step 3: Verify Docker Is Installed

Check Docker’s version to confirm the installation:

docker --version

You should see something like:

To test Docker is working:

Docker version 24.x.x, build abcdefg
sudo docker run hello-world

This will download and run a simple test container that prints “Hello from Docker!”


🔓 Step 4: Run Docker Without Sudo (Optional but Recommended)

By default, you need to use sudo with every Docker command. That can get annoying fast. Let’s fix that.

1. Create the docker group (if it doesn’t already exist):

sudo groupadd docker

2. Add your user to the docker group:

sudo usermod -aG docker $USER

3. Apply the new group membership:

You can log out and log back in, or simply run:

4. Now test it without sudo:

docker run hello-world

If you see the same output without an error, you’re all set! 🎉


🧪 Bonus: A Quick Docker Command

Want to try something more fun? Run an Nginx container:

docker run -d -p 8080:80 nginx

Then visit http://localhost:8080 in your browser and see the default Nginx welcome page!


📝 Final Thoughts

That’s it—you now have Docker installed on Ubuntu, and you can run it without needing sudo every time. Whether you’re using it for local dev, building images, or deploying apps, you’re ready to start containerizing all the things!


🔧 What’s Next?

  • Learn about Docker Compose to manage multi-container apps.
  • Build your own Dockerfile and custom containers.
  • Dive into Kubernetes if you’re ready to scale!

If you want a follow-up post on Docker best practices, building your first image, or setting up a dev environment—just let me know!

Happy Dockering! ✨

Leave a Reply

Your email address will not be published. Required fields are marked *