Blog / Detailed Guide to Installing Docker on Ubuntu, Windows, and macOS
Detailed Guide to Installing Docker on Ubuntu, Windows, and macOS
A step-by-step guide for developers on how to install Docker Engine and Docker Desktop on Ubuntu, Windows, and macOS, including permission configuration and post-installation verification.
Mục lục
- Understanding Docker Engine vs. Docker Desktop
- 1. Installing Docker Engine on Ubuntu
- Step 1: Uninstall old versions (if any)
- Step 2: Set up the Docker repository
- Step 3: Install Docker packages
- Step 4: Configure Docker to run without sudo
- 2. Installing Docker Desktop on Windows
- System Requirements
- Installation Steps
- 3. Installing Docker Desktop on macOS
- Installation Steps
- Verifying the Installation
- Essential Commands to Remember
- From Local Environment to the Cloud
Docker has become a familiar tool for most developers today. Packaging an application along with all its dependencies into a container completely eliminates the "it works on my machine, but fails on the server" problem. In this article, we will walk through the step-by-step installation of Docker on the three most popular operating systems: Ubuntu (Linux), Windows, and macOS.
Understanding Docker Engine vs. Docker Desktop#
Before getting started, you should understand two basic concepts to choose the right version to install:
- Docker Engine: The core component that runs directly on the Linux operating system, including the Docker daemon (
dockerd) and the Docker CLI command-line tool (docker). This is a lightweight version commonly used on Linux servers or workstations. - Docker Desktop: A graphical application suite for Windows, macOS, and Linux. Under the hood, it automatically creates a lightweight Linux virtual machine to run Docker Engine, bundled with Docker Compose and convenient management tools.
1. Installing Docker Engine on Ubuntu#
On Ubuntu, the best approach is to install from Docker's official repository to ensure you always receive the latest updates.
Step 1: Uninstall old versions (if any)#
If your machine previously had unofficial packages installed, remove them to avoid conflicts:
sudo apt-get remove docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runcStep 2: Set up the Docker repository#
Update the package index and install tools to allow Apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install 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.ascNext, add the Docker repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get updateStep 3: Install Docker packages#
Install the latest version of Docker Engine, CLI, containerd, and the Docker Compose plugin:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginStep 4: Configure Docker to run without sudo#
By default, Docker requires root privileges. To run the docker command directly from your current user account, add your user to the docker group:
sudo usermod -aG docker $USER
newgrp dockerNote: You may need to log out and log back in for this change to take full effect.
2. Installing Docker Desktop on Windows#
On Windows, the most efficient way to run Docker is through the WSL 2 (Windows Subsystem for Linux 2) backend.
System Requirements#
- Windows 10 64-bit (version 21H2 or higher) or Windows 11 64-bit.
- Hardware Virtualization enabled in BIOS/UEFI.
Installation Steps#
- Enable WSL 2: Open PowerShell or Command Prompt as Administrator and run:
``powershell wsl --install `` Restart your computer if prompted.
- Download the installer: Visit the official Docker website and download
Docker Desktop Installer.exefor Windows.
- Run the installer: Double-click the downloaded file. On the configuration screen, make sure the Use WSL 2 instead of Hyper-V option is checked.
- Finish: Once the installation is complete, click Close and restart to reboot your computer. After restarting, open Docker Desktop from the Start Menu and accept the terms of service.
3. Installing Docker Desktop on macOS#
For Mac users, make sure to choose the version that matches your Mac's processor architecture.
Installation Steps#
- Check your chip type: Click the Apple icon in the top-left corner and select About This Mac. Check whether your Mac uses an Intel Chip or Apple Silicon (M1, M2, M3...).
- Download `Docker.dmg`: Download the appropriate installer for your chip from the official Docker website.
- Install the application: Open the downloaded
Docker.dmgfile and drag the Docker icon into the Applications folder. - Launch: Open Docker from the Applications folder. The system will prompt for your macOS password to grant permissions for setting up networking and background services for containers.
On Apple Silicon Macs, if you need to run images built exclusively for the amd64 (x86_64) architecture, it is recommended to install Rosetta 2 by running the following command in Terminal:
softwareupdate --install-rosettaVerifying the Installation#
Regardless of which operating system you use, once the installation is complete, open Terminal (or PowerShell on Windows) and check the versions:
docker --version
docker compose versionNext, test by running the hello-world container to ensure the Docker daemon can pull images from Docker Hub and start containers properly:
docker run --rm hello-worldIf you see the message Hello from Docker! along with some informational text below it, your Docker environment is working perfectly.
Essential Commands to Remember#
To get up to speed quickly, keep these everyday management commands handy:
docker ps: List running containers.docker ps -a: List all containers (including stopped ones).docker images: List images stored locally on your machine.docker stop <container_id>: Stop a running container.docker system prune: Clean up stopped containers and unused images to free up disk space.
From Local Environment to the Cloud#
After installing Docker, you can easily spin up databases or package your applications using a Dockerfile right on your local machine. When your application is ready for production, instead of renting a virtual server and repeating the Docker installation and maintenance steps above, you can use a cloud PaaS platform. Simply push your code via git push, and the system will automatically build your application, connect it to one-click databases, and issue free HTTPS certificates.
Wishing you a successful setup and a smoother software development experience with Docker!