I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+91-9723273747

Email

contact@manojitaliya.com

Address

Surat, Gujarat, INDIA

Social Links

Web Servers

How to Install Docker on Ubuntu (Beginner to Pro Guide)

Learn how to install Docker on Ubuntu 22.04, 20.04, or 18.04 with this complete guide. Covers Docker Engine, Docker CLI, Docker Compose, and secure setup using official repositories. Step-by-step commands and detailed instructions make it easy for beginners and developers to get started with containerized apps on Linux.

How to Install Docker on Ubuntu (Beginner to Pro Guide)

Docker is a platform that allows developers to build, test, and run applications inside isolated environments called containers. It’s fast, lightweight, and ideal for development, testing, and deployment.

In this guide, you’ll learn how to install Docker on an Ubuntu system step-by-step, with complete explanations for every command.

This guide supports: Ubuntu 22.04, 20.04, and 18.04.

System Requirements

  • Ubuntu installed (18.04 or later)
  • Sudo (admin) user access
  • Internet connection

Step 1: Update Your Ubuntu System

Before installing anything, make sure your package list and installed packages are up to date.

sudo apt update
sudo apt upgrade -y

This ensures compatibility with the latest Docker version.

Step 2: Install Required Dependencies

Install packages that let APT use repositories over HTTPS and help securely fetch Docker’s key.

sudo apt install ca-certificates curl gnupg lsb-release
  • ca-certificates: Required for SSL communication
  • curl: For downloading files from the internet
  • gnupg: For verifying package authenticity
  • lsb-release: To identify your Ubuntu version dynamically

Step 3: Add Docker’s GPG Key

Docker signs its packages. You need to add their GPG key to verify the authenticity of packages.

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

This saves Docker’s GPG key in a secure format used by APT.

Step 4: Add Docker Repository

Now, add Docker’s official repository to your APT sources list:

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

This ensures your system installs Docker from Docker Inc., not the Ubuntu archive.

Step 5: Update Package Index Again

After adding the Docker repo, reload your package index:

sudo apt update

You should now see packages from download.docker.com if you run:

apt-cache policy docker-ce

Step 6: Install Docker Engine & Docker Compose

This command installs Docker, Docker CLI, container runtime, and Docker Compose plugin:

sudo apt install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
  • docker-ce: Community Edition (the actual Docker engine)
  • docker-ce-cli: Command-line interface to interact with Docker
  • containerd.io: Lightweight container runtime
  • docker-compose-plugin: Native support for Compose v2

Step 7: Verify Docker Installation

Check that Docker is installed and working:

sudo docker --version

Now test Docker by running a container:

sudo docker run hello-world

This pulls and runs a test image from Docker Hub. If successful, you’ll see a confirmation message from Docker.

Step 8: (Optional) Run Docker Without sudo

To avoid typing sudo every time, add your user to the docker group:

sudo usermod -aG docker $USER

Important: You must log out and log back in (or reboot) for changes to take effect.

After that, you can run:

docker ps

...without needing sudo.

Step 9: Enable Docker to Start at Boot

Ensure Docker starts automatically when the server reboots:

sudo systemctl enable docker

Step 10: Uninstall Docker (If Needed)

If you ever need to remove Docker:

sudo apt remove docker-ce docker-ce-cli containerd.io

To delete all data:

sudo rm -rf /var/lib/docker

FAQs

Can I use this guide on Ubuntu 22.04?

Yes, it works perfectly for 22.04 and all recent LTS versions including 20.04 and 18.04.

Why use Docker’s official repository instead of Ubuntu’s default?

The official Docker repository always provides the latest stable version with critical updates and bug fixes faster than the Ubuntu-maintained version.

How do I check if Docker is running?

sudo systemctl status docker

How can I stop/start/restart Docker?

sudo systemctl stop docker
sudo systemctl start docker
sudo systemctl restart docker

How do I check running containers?

docker ps

How do I list all containers (including stopped ones)?

docker ps -a

Conclusion

You now have Docker fully installed and configured on Ubuntu. With Docker up and running, you can:

  • Run containers like Nginx, MySQL, Redis, and WordPress
  • Use docker-compose for multi-container apps
  • Build and share custom Docker images

If you’re ready to take the next step, explore Docker Compose or Kubernetes integration.

Need help deploying real-world apps with Docker? Let me know and I’ll write tutorials for WordPress, Node.js, and more!

dockerubuntu
4 min read
Jun 24, 2025
By MANOJ ITALIYA
Share

Leave a comment

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

Related posts

Jun 24, 2025 • 4 min read
How to Install Nginx on Ubuntu 22.04 (Step-by-Step Guide)
Jun 24, 2025 • 4 min read
How to Install WordPress on Ubuntu
Your experience on this site will be improved by allowing cookies. Cookie Policy