Install Docker on Ubuntu, Windows, and macOS
This beginner guide explains how to install Docker, verify the installation, run your first container, and fix common setup issues.
Before you install Docker
Docker can be installed in different ways depending on your operating system. On Linux servers, Docker Engine is common. On Windows and macOS, Docker Desktop is commonly used because it includes the Docker CLI, Docker Engine integration, Compose support, and a desktop interface.
Install Docker on Ubuntu
For Ubuntu, the recommended production approach is to follow Docker’s official repository-based installation. Below is a simplified learning workflow. Always compare commands with the official Docker documentation before using in production.
Install the prerequisite packages, add Docker’s signed package repository using the current official instructions, refresh the package index, and install Docker Engine, the command-line client, containerd, Buildx, and the Compose plug-in.
Verify Docker on Ubuntu
docker --version sudo docker run hello-world
Run Docker without sudo
Add your current account to the docker group with the usermod command newgrp docker docker run hello-world
Install Docker on Windows
- Install Docker Desktop for Windows from Docker’s official site.
- Enable WSL 2 if Docker Desktop asks for it.
- Restart your system if required.
- Open PowerShell and run verification commands.
docker --version docker compose version docker run hello-world
Install Docker on macOS
- Download Docker Desktop for Mac from Docker’s official site.
- Choose the correct Apple Silicon or Intel version.
- Drag Docker to Applications.
- Start Docker Desktop and wait until Docker is running.
docker --version docker run hello-world
First useful container
docker run -d --name web -p 8080:80 nginx
Open http://localhost:8080 in your browser, or http://SERVER_IP:8080 when testing on a remote Ubuntu server with intentionally permitted network access. Stop and remove the container afterward:
docker stop web docker rm web
Common errors
- Error — Meaning — Fix
- Cannot connect to Docker daemon — Docker service is not running — Start Docker service or Docker Desktop.
- Permission denied — User cannot access Docker daemon — Use sudo or add user to docker group carefully.
- Port already allocated — Host port is already used — Use another port like 8081:80.
Best practices
- Use official installation documentation for production systems.
- Verify installation with hello-world .
- Keep Docker updated.
- Do not run random images from untrusted sources.
- Understand Docker group permissions on Linux.
Backlinks
- Docker Learning Path
- What is Docker?
Official references
- Install Docker Engine on Ubuntu
- Install Docker Desktop on Windows
- Install Docker Desktop on Mac
Ubuntu: install Docker Engine from the official apt repository
For supported 64-bit Ubuntu releases, Docker recommends installing from its apt repository. Review the official prerequisites and conflicting-package guidance first. Do not run these commands on a host with existing Docker workloads until you have inspected how containers and network rules will be affected. This is an illustrative installation workflow, not a claim of a test on your machine.
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
sudo tee /etc/apt/sources.list.d/docker.sources > /dev/null <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl status docker --no-pager
sudo docker run --rm hello-worldExpected result: docker --version shows an installed CLI; docker compose version reports the Compose plugin; the hello-world container prints a success message and exits. If Docker fails to start, inspect sudo systemctl status docker and sudo journalctl -u docker --no-pager -n 100 before changing firewall rules.
Windows and macOS prerequisites
| Platform | Recommended setup | Verification |
|---|---|---|
| Windows 10/11 supported editions | Install Docker Desktop and use supported WSL 2 or Hyper-V backend; ensure virtualization and the required OS build are available | Open Docker Desktop; run docker version, docker compose version and docker run --rm hello-world in PowerShell |
| macOS Apple silicon or Intel | Install Docker Desktop for the correct chip and supported macOS version; allow needed permissions | Launch Docker Desktop and run docker version and docker run --rm hello-world in Terminal |
| Ubuntu server | Install Docker Engine packages from the official repository and review daemon security | Run sudo systemctl status docker and sudo docker run --rm hello-world |
Permissions and networking safety
Members of the docker group effectively have root-level control on the host through the Docker socket. Prefer sudo docker or rootless Docker where suitable rather than casually granting access. Publishing -p 8080:80 binds the host port broadly by default; for local-only testing, prefer -p 127.0.0.1:8080:80. Docker-published ports may bypass some host firewall expectations, including ufw; review the official packet-filtering guidance before exposing a container.
docker run -d --name melochip-nginx-demo -p 127.0.0.1:8080:80 nginx:stable
# From the same machine, open http://localhost:8080
# Remove only the demo container when finished:
docker stop melochip-nginx-demo
docker rm melochip-nginx-demoTroubleshooting by symptom
| Symptom | Check | Likely action |
|---|---|---|
| Cannot connect to Docker daemon | docker version; systemctl status docker (Linux) or Docker Desktop status | Start the daemon or Desktop; verify your selected Docker context |
| Permission denied on /var/run/docker.sock | id; ls -l /var/run/docker.sock | Use sudo or consider rootless mode; evaluate docker-group privilege |
| Port 8080 already allocated | ss -ltn (Linux) or netstat (platform-specific) | Choose another local port or stop the conflicting service |
| WSL 2 backend unavailable on Windows | wsl --status in PowerShell; check virtualization support | Update or enable WSL and meet the Docker Desktop Windows prerequisites |
Official documentation: https://docs.docker.com/engine/install/ubuntu/ , https://docs.docker.com/desktop/setup/install/windows-install/ and https://docs.docker.com/desktop/setup/install/mac-install/ . Related Melochip guide: https://melochip.com/posts/what-is-docker-complete-beginner-guide-with-examples .
Join the discussion
0 CommentsAsk questions, add context, or share what worked.
More from Melochip Editorial
Learn what Playwright testing is, why modern QA teams use it, how testers can get started, and the major types...
8 min read · Updated Nov 16, 2026
Learn how Kubernetes Deployments and ReplicaSets work with practical YAML, scaling, self-healing, rolling upda...
7 min read · Updated Nov 16, 2026
Learn Kubernetes security best practices with RBAC, Secrets, ServiceAccounts, Pod securityContext, NetworkPoli...
6 min read · Updated Nov 16, 2026Related articles
Learn Docker registries, image tags, Docker Hub, private registries, login, push, pull, naming rules, CI/CD us...
3 min read · Updated Nov 16, 2026
Learn Docker environment variables and secrets, including docker run -e, env files, Compose environment, secre...
3 min read · Updated Nov 16, 2026
Prepare for Docker interviews with practical questions and real-time scenarios covering images, containers, Do...
3 min read · Updated Nov 16, 2026
Learn Docker security best practices for images, containers, users, secrets, registries, scanning, least privi...
2 min read · Updated Nov 16, 2026Stay in the loop. Get new Melochip articles
Receive Melochip article updates when new articles are available. Explicit opt-in only.
No comments yet. Start the discussion.