Containerization revolutionizes application deployment by encapsulating software in isolated, lightweight environments. Docker, the industry-leading platform, simplifies this process, enabling developers to build, ship, and run applications consistently across systems. This guide walks you through install Docker on Ubuntu Server and executing your first containerized application.
Prerequisites
Before installing Docker, ensure your Ubuntu Server meets these requirements:
- Ubuntu 20.04 LTS or later (64-bit).
- sudo privileges or root access.
- Stable internet connection for downloading packages.
Step 1: Install Docker on Ubuntu Server
Update System Packages
sudo apt update && sudo apt upgrade -y
Install Required Dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
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
Set Up 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
Install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io -y
Verify Installation
sudo docker run hello-world
If successful, you’ll see a confirmation message like below.

Step 2: Managing Docker as a Non-Root User
By default, Docker requires sudo
privileges. To avoid typing sudo
repeatedly:
- Create a Docker Group (if not exists):
sudo groupadd docker
- Add Your User to the Group:
sudo usermod -aG docker $USER
- Apply Changes:
newgrp docker
Step 3: Running Your First Container
Launch a Nginx web server in seconds:
docker run -d -p 8080:80 --name my-nginx nginx
-d
: Run in detached mode.-p 8080:80
: Map host port 8080 to container port 80.--name
: Assign a custom name to the container.
Verify Access:
curl http://localhost:8080

Step 4: Essential Docker Commands
Command | Description |
---|---|
docker ps | List running containers |
docker images | View downloaded images |
docker stop <container-id> | Stop a container |
docker rm <container-id> | Remove a container |
docker rmi <image-id> | Delete an image |
Step 5: Automate Workflows with Docker Compose
For multi-container applications, use Docker Compose:
- Install Docker Compose:
sudo apt install docker-compose -y
- Create a
docker-compose.yml
File:
version: '3'
services:
web:
image: nginx
ports:
- "8080:80"
- Start the Stack:
docker-compose up -d

Best Practices for Docker on Ubuntu
- Regularly Update Docker:
sudo apt update && sudo apt upgrade docker-ce -y
- Clean Unused Resources:
docker system prune -a
- Use Official Images from Docker Hub for security and reliability.
Troubleshooting Common Issues
- Permission Denied: Ensure your user is in the
docker
group. - Port Conflicts: Check for other services using the same port.
- Image Pull Errors: Verify internet connectivity and image name spelling.
Docker vs. Other Containerization Tools
While Docker dominates the containerization landscape, understanding alternatives helps choose the right tool for your use case:
Tool | Type | Key Features | Best For |
---|---|---|---|
Docker | Application Containers | – Focus on portable, app-centric packaging<br>- Huge ecosystem (Docker Hub)<br>- Simple CLI and Compose | Developers, microservices, CI/CD workflows |
LXD | System Containers | – Full OS environments (like lightweight VMs)<br>- Tight integration with LXC/Linux<br>- Advanced resource management | Infrastructure-as-a-service, hypervisor replacement |
Podman | Application Containers | – Daemonless architecture<br>- Rootless by default<br>- Docker-compatible CLI | Security-focused workloads, edge computing |
containerd | Container Runtime | – Low-level runtime (used by Docker/Kubernetes)<br>- Minimalist design<br>- Focus on scalability | Kubernetes clusters, large-scale deployments |
CRI-O | Kubernetes Runtime | – Optimized for Kubernetes CRI<br>- Lightweight & secure<br>- Red Hat-backed | OpenShift/OKD clusters, Kubernetes-native ops |
Why Docker Still Shines
- Beginner-friendly: Simplified workflow for app development and testing.
- Portability: Containers run identically across macOS, Windows, and Linux.
- Community support: Over 8 million Docker Hub images and extensive documentation.
When to Consider Alternatives
- LXD: Need full OS isolation (e.g., hosting multiple services with separate users).
- Podman: Prioritize security (e.g., government/healthcare workloads).
- containerd/CRI-O: Building Kubernetes-native infrastructure.
Conclusion
By following this guide, you’ve installed Docker on Ubuntu Server and deployed your first containerized application. Docker’s flexibility makes it indispensable for DevOps, cloud-native development, and hybrid environments. Explore advanced features like Docker Swarm or Kubernetes integration to scale your container workloads.
Reference: Docker Official Documentation
What’s Next? Get Ready to Explore LXD for Linux Containers
Now that you’ve mastered Docker for application containerization, let’s dive deeper into the world of Linux system containers! Stay tuned for our upcoming guide:
“Introduction to LXD for Linux Containers: Lightweight Virtualization Made Simple”
In this next article, you’ll learn:
- How LXD differs from Docker: While Docker focuses on application containers, LXD specializes in full Linux system containers that behave like lightweight virtual machines.
- Installation and setup: Configure LXD on Ubuntu Server for isolated, scalable environments.
- Use cases: Deploy entire OS instances, test configurations, or create development environments with minimal overhead.
- Integration with Docker: Combine LXD’s system-level isolation with Docker’s application portability for hybrid workflows.
Why LXD?
- Ideal for scenarios requiring closer-to-metal performance or complete OS environments.
- Simplified management of storage, networking, and resource allocation.
- Enhanced security profiles for multi-tenant systems.
1 thought on “How to Install Docker on Ubuntu Server: A Step-by-Step Guide to Containerization”