Docker has revolutionized how we build, ship, and run applications. Whether you're a developer, DevOps engineer, or system administrator, learning Docker is essential. This comprehensive guide will walk you through installing Docker and Docker Compose on various operating systems.
What is Docker?
Docker is a platform that enables developers to package applications into containers—standardized executable components that combine application source code with all the operating system libraries and dependencies required to run that code in any environment.
Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services, networks, and volumes.
Prerequisites
Before installing Docker, ensure your system meets these requirements:
- Operating System: Ubuntu 20.04+, Debian 11+, CentOS 7+, macOS 10.15+, or Windows 10/11 Pro
- System Architecture: 64-bit processor
- Virtualization: Must be enabled in BIOS (for Windows/macOS)
- Minimum RAM: 4GB recommended
- Sudo/Administrator privileges: Required for installation
Part 1: Installing Docker on Ubuntu/Debian (One-Click Script)
Instead of manual installation, we'll use Docker's official convenience script for a faster, easier installation process.
Step 1: Download and Run the Official Installation Script
Docker provides an official installation script that automatically handles all dependencies and configurations:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
This script will:
- Detect your OS version
- Add Docker's official repository
- Install all required dependencies
- Install Docker Engine, CLI, and containerd
- Start the Docker service
Step 2: Verify Docker Installation
Check that Docker is installed and running:
sudo docker --version
sudo systemctl status docker
Step 3: Add Your User to the Docker Group (Optional)
To run Docker commands without sudo:
sudo usermod -aG docker $USER
Important: Log out and log back in for this to take effect, or run:
newgrp docker
Step 4: Test Docker Installation
Run the hello-world container to verify everything works:
docker run hello-world
You should see a welcome message confirming Docker is working correctly.
Step 5: Clean Up Installation Script (Optional)
Remove the installation script:
rm get-docker.sh
Note: The convenience script is recommended for development and testing environments. For production systems, consider using your package manager for more control over versions and updates.
Part 2: Installing Docker on CentOS/RHEL (One-Click Script)
Similar to Ubuntu/Debian, we'll use Docker's official convenience script:
Step 1: Download and Run the Installation Script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Step 2: Start and Enable Docker
sudo systemctl start docker
sudo systemctl enable docker
Step 3: Add User to Docker Group
sudo usermod -aG docker $USER
newgrp docker
Step 4: Verify Installation
sudo docker --version
docker run hello-world
Step 5: Clean Up
rm get-docker.sh
Part 3: Installing Docker on macOS
Step 1: Download Docker Desktop
- Visit the Docker Desktop for Mac download page
- Download the appropriate version for your Mac (Intel or Apple Silicon)
Step 2: Install Docker Desktop
- Open the downloaded
.dmgfile - Drag the Docker icon to your Applications folder
- Double-click
Docker.appin Applications to start Docker
Step 3: Complete Setup
- Accept the terms and conditions
- Enter your system password when prompted (Docker needs privileged access)
- Wait for Docker to start (the whale icon in the menu bar will stop animating)
Step 4: Verify Installation
Open Terminal and run:
docker --version
docker run hello-world
Part 4: Installing Docker on Windows
Step 1: System Requirements
Ensure you have:
- Windows 10/11 64-bit: Pro, Enterprise, or Education
- Hardware virtualization enabled in BIOS
- WSL 2 feature enabled
Step 2: Enable WSL 2
Open PowerShell as Administrator and run:
wsl --install
Restart your computer when prompted.
Step 3: Download Docker Desktop
- Visit Docker Desktop for Windows
- Download the installer
Step 4: Install Docker Desktop
- Run the installer
- Follow the installation wizard
- Ensure "Use WSL 2 instead of Hyper-V" is selected
- Restart your computer when installation completes
Step 5: Start Docker Desktop
- Launch Docker Desktop from the Start menu
- Accept the service agreement
- Wait for Docker to start
Step 6: Verify Installation
Open PowerShell or Command Prompt:
docker --version
docker run hello-world
Part 5: Installing Docker Compose
Docker Compose comes pre-installed with Docker Desktop on macOS and Windows. For Linux users, follow these steps:
Method 1: Install Docker Compose Plugin (Recommended)
The easiest way on modern Docker installations:
sudo apt update
sudo apt install docker-compose-plugin
Verify installation:
docker compose version
Method 2: Install Standalone Docker Compose
For systems that need the standalone version:
Step 1: Download Docker Compose Binary
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Step 2: Apply Executable Permissions
sudo chmod +x /usr/local/bin/docker-compose
Step 3: Create Symbolic Link (Optional)
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Step 4: Verify Installation
docker-compose --version
Testing Your Docker Setup
Let's create a simple Docker Compose application to test everything:
Step 1: Create Project Directory
mkdir ~/docker-test && cd ~/docker-test
Step 2: Create docker-compose.yml
Create a file named docker-compose.yml:
version: '3.8'
services:
web:
image: nginx:alpine
ports:
- "8080:80"
volumes:
- ./html:/usr/share/nginx/html
Step 3: Create HTML Directory and File
mkdir html
echo "<h1>Docker is working!</h1>" > html/index.html
Step 4: Start the Application
docker compose up -d
Step 5: Test in Browser
Open your browser and navigate to http://localhost:8080
You should see "Docker is working!"
Step 6: Stop the Application
docker compose down
Useful Docker Commands
Here are essential Docker commands you'll use frequently:
Container Management
docker ps # List running containers
docker ps -a # List all containers
docker stop <container> # Stop a container
docker start <container> # Start a container
docker restart <container> # Restart a container
docker rm <container> # Remove a container
docker logs <container> # View container logs
Image Management
docker images # List images
docker pull <image> # Download an image
docker rmi <image> # Remove an image
docker build -t <name> . # Build image from Dockerfile
System Commands
docker system df # Show Docker disk usage
docker system prune # Remove unused data
docker volume ls # List volumes
docker network ls # List networks
Troubleshooting Common Issues
Issue 1: Permission Denied
Problem: Getting "permission denied" errors
Solution: Add your user to the docker group:
sudo usermod -aG docker $USER
newgrp docker
Issue 2: Docker Daemon Not Running
Problem: "Cannot connect to Docker daemon"
Solution:
sudo systemctl start docker
sudo systemctl enable docker
Issue 3: Port Already in Use
Problem: "Port is already allocated"
Solution: Change the port in your docker-compose.yml or stop the conflicting service.
Issue 4: Disk Space Issues
Problem: Running out of disk space
Solution: Clean up unused Docker resources:
docker system prune -a --volumes
Best Practices
Keep Docker Updated: Regularly update Docker to get security patches and new features
Use Official Images: When possible, use official Docker images from Docker Hub
Don't Run as Root: Use the docker group instead of running docker commands with sudo
Clean Up Regularly: Remove unused containers, images, and volumes to save disk space
Use .dockerignore: Create
.dockerignorefiles to exclude unnecessary files from your Docker buildsMonitor Resources: Keep an eye on container resource usage with
docker statsUse Docker Compose for Multi-Container Apps: It's much easier than managing multiple containers manually
Next Steps
Now that you have Docker and Docker Compose installed, here are some next steps:
- ✅ Learn about Dockerfiles and how to create custom images
- ✅ Explore Docker Hub for ready-to-use images
- ✅ Practice with docker-compose for multi-container applications
- ✅ Learn about Docker volumes for persistent data
- ✅ Study Docker networking concepts
- ✅ Explore container orchestration with Kubernetes
Conclusion
Congratulations! 🎉 You've successfully installed Docker and Docker Compose on your system using the simplified one-click installation method. Docker is a powerful tool that will streamline your development workflow and make deploying applications much easier.
Remember:
- Docker packages applications into portable containers
- Docker Compose helps manage multi-container applications
- The one-click script simplifies installation for development environments
- Practice makes perfect—start containerizing your projects!
Have questions or run into issues? Drop them in the comments below!
Happy Dockerizing! 🐳
Top comments (0)