Docker Installation and Setup
Docker Engine vs. Docker Desktop
The installation process differs based on your operating system.
For Linux: You will install Docker Engine, a set of command-line tools and a background daemon (
dockerd) that run natively on your host.For Windows and macOS: You will install Docker Desktop. This is a comprehensive desktop application that includes the Docker Engine, the client, Docker Compose, and Kubernetes. Because Linux containers can only run on a Linux kernel, Docker Desktop for Windows and Mac runs these components inside a lightweight, managed Linux virtual machine.
On Windows, this is achieved via the Windows Subsystem for Linux (WSL) 2.
On macOS, this is achieved via the Hypervisor framework.
This guide covers the two most common development environments: a native Ubuntu (Linux) server and a Windows 11 machine using WSL2.
Installation on Ubuntu 22.04 / 24.04
This process installs Docker Engine from Docker's official apt repository, which ensures you always have the latest version.
Reference: Official Docker Documentation for Ubuntu
1. Remove Old Versions
First, remove any older, conflicting Docker packages that may have been installed from Ubuntu's default repositories or other sources.
sudo apt-get remove -y docker docker-engine docker.io containerd runc docker-doc docker-compose docker-compose-v2 podman-docker2. Set Up the Repository
Next, configure apt to use Docker's official GPG key and repository.
- Update apt and install prerequisite packages
sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl- Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL [https://download.docker.com/linux/ubuntu/gpg](https://download.docker.com/linux/ubuntu/gpg) -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc- Add the repository to Apt sources: This command dynamically finds your Ubuntu codename (e.g., "jammy" or "noble")
echo \
"deb [arch=$(dpkg --print-architecture) \
signed-by=/etc/apt/keyrings/docker.asc] \
[https://download.docker.com/linux/ubuntu](https://download.docker.com/linux/ubuntu) \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null- Update apt again to pull from the new Docker repo
sudo apt-get update3. Install Docker Engine
Now that the repository is set up, you can install the latest version of the Docker Engine, client, and plugins.
# Install the latest stable version of Docker
sudo apt-get install -y docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin4. Uninstall Docker Engine
If you need to remove Docker:
- Uninstall the Docker Engine, CLI, containerd, and Docker Compose packages:
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras- Images, containers, volumes, or custom configuration files on your host aren't automatically removed. To delete all images, containers, and volumes:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd- Remove the Docker
aptsource and GPG key:
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.ascInstallation on Windows 11
The recommended (and required) method for running Docker on Windows is by using Docker Desktop with the WSL 2 (Windows Subsystem for Linux) backend.
Reference : Official Docker Documentation for Windows
https://www.docker.com/products/docker-desktop/
1. Enable WSL 2 and Virtualization
Before installing Docker Desktop, you must enable the required Windows features.
Open PowerShell or Command Prompt as Administrator.
Enable the Windows Subsystem for Linux:
powershellwsl --installThis single command will enable the necessary features, download the latest Linux kernel, and set WSL 2 as the default. It will also install the default Ubuntu distribution.
Note: If you have an older version of Windows, you may need to run these commands manually:
powershelldism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestartRestart your computer as prompted to complete the setup.
2. (Optional) Install a Linux Distribution
If the wsl --install command did not install a distribution, or if you prefer a different one, you can get one from the Microsoft Store. Open the store and search for "Ubuntu" or "Debian" and click "Install".
3. Install Docker Desktop
Go to the official Docker website and download the Docker Desktop for Windows installer: https://www.docker.com/products/docker-desktop/
Run the downloaded
.exeinstaller.Follow the on-screen prompts. Ensure that the "Use WSL 2 instead of Hyper-V (recommended)" option is CHECKED.
Once the installation is complete, Docker Desktop will start. The whale icon in the system tray indicates its status. It may take a minute to start the Docker Engine.
Docker Desktop will automatically detect your WSL 2 distributions and integrate with them.
Post-Installation Steps
For Linux (Ubuntu)
1. Manage Docker as a Non-Root User (Highly Recommended)
By default, the Docker daemon socket is owned by root, which means you must use sudo for every Docker command. To avoid this, add your user to the docker group (which is created by the installer).
# 1. Add your user to the 'docker' group
sudo usermod -aG docker $USER# 2. IMPORTANT: You must log out and log back in
# for this group change to take effect.
#
# Alternatively, run this command to activate the
# changes for your current terminal session:
newgrp dockerSecurity Warning: Adding a user to the docker group is equivalent to giving them root access to the host.
2. Configure Docker to Start on Boot
The Docker Engine service is automatically configured to start on boot. You can verify and manage this with systemd.
# Check if the services are running and enabled
sudo systemctl status docker
sudo systemctl status containerd
# (If needed) Enable the services to start at boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
# (If needed) Start the services manually
sudo systemctl start docker.service
sudo systemctl start containerd.service3. Configure Container Logging
Docker provides logging drivers for collecting and viewing log data. The default driver, json-file, writes log data to files on the host filesystem. Over time, these log files can expand and exhaust disk resources. It is a best practice to configure log rotation in the Docker daemon's configuration file (/etc/docker/daemon.json).
For Windows (Docker Desktop)
Docker Desktop will automatically start when you log in to Windows. You can configure this behavior in Settings > General. It automatically manages the lifecycle of the Docker Engine within its WSL 2 virtual machine.
Verify the Installation
You can test that your installation is working correctly by running the hello-world container.
# This command downloads a minimal test image and runs it.
# It will print a confirmation message if successful.
docker run hello-world(Note: Omit 'sudo' if you added your user to the 'docker' group)
After you see the "Hello from Docker!" message, you can test with a more interactive container, like a shell in a lightweight Alpine Linux image:
# This will pull the 'alpine' image, start a container,
# and drop you into an interactive shell ('/bin/sh').
# --rm = automatically remove the container when you exit
# -it = interactive TTY (a terminal)
docker container run --rm -it alpine /bin/shIf you see a command prompt (e.g., / #), your installation is fully functional. Type exit to leave the container.
docker container run --rm -ti docker.io/fedora:latest /bin/bash
docker container run --rm -ti docker.io/fedora:latest /bin/bashdocker.io/ubuntu:latest, docker.io/fedora:latest, and docker.io/alpine:latest all represent a Docker image repository, followed by an image name and an image tag.
References
General Installation: https://docs.docker.com/get-docker
Docker Desktop for Linux: https://docs.docker.com/desktop/linux/install
Docker Engine for Ubuntu: https://docs.docker.com/engine/install/ubuntu/
Docker Desktop for Windows: https://docs.docker.com/desktop/install/windows-install/
Windows Subsystem for Linux (WSL): https://docs.microsoft.com/en-us/windows/wsl/install
Docker Daemon (
dockerd) Reference: https://docs.docker.com/engine/reference/commandline/dockerdProxy Configuration: https://docs.docker.com/network/proxy
Deprecated Features: https://docs.docker.com/engine/deprecated
