How to Install Docker on Windows: A Step-by-Step Guide
Docker is a popular platform for containerizing applications, making development, deployment, and management easier across various environments. In this guide, we’ll walk through the steps to install Docker on Windows.
Prerequisites
Before installing Docker on Windows, ensure the following:
- Operating System: Windows 10 (Pro, Enterprise, or Education) or Windows 11. Docker Desktop requires the WSL 2 (Windows Subsystem for Linux) backend to run on Windows.
- Hardware Requirements: At least 4GB of RAM.
Step 1: Enable Windows Subsystem for Linux (WSL 2)
Docker uses WSL 2 as its backend on Windows, so you need to enable it first.
1.1. Enable WSL
- Open PowerShell as an administrator.
- Run the following command to enable WSL:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
1.2. Enable Virtual Machine Platform
To run the WSL 2 backend, you need to enable the Virtual Machine Platform feature.
- Run the following command in PowerShell:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
1.3. Set WSL Version 2 as the Default
- Restart your computer.
- Once your system restarts, open PowerShell again and set WSL 2 as the default version by running:
wsl --set-default-version 2
1.4. Install a Linux Distribution
To finish setting up WSL, you need to install a Linux distribution. You can do this from the Microsoft Store.
- Open the Microsoft Store.
- Search for a distribution like Ubuntu and click Install.
- Once installed, launch the distribution, and it will prompt you to create a username and password.
Step 2: Install Docker Desktop for Windows
Docker Desktop provides a user-friendly way to run Docker containers on Windows. Follow the steps below to install Docker Desktop.
2.1. Download Docker Desktop
- Go to the Docker Desktop for Windows page.
- Click Download for Windows.
2.2. Run the Docker Installer
- Once the download is complete, open the installer.
- In the Docker Desktop Setup, check the option to enable WSL 2 and click OK.
- Click Next to proceed through the installation.
- Once the installation is finished, click Close.
2.3. Configure Docker for WSL 2
After installation, Docker Desktop will prompt you to configure WSL 2 as its backend.
- Open Docker Desktop.
- Go to Settings > General.
- Ensure that Use the WSL 2 based engine is checked.
- Click Apply & Restart to make the changes.
2.4. Link Docker to Your Linux Distribution
Docker allows you to use your installed WSL distributions to run containers. To enable this:
- In Docker Desktop, go to Settings > Resources > WSL Integration.
- Enable the integration for the distributions you want to use with Docker.
Step 3: Verify Docker Installation
To confirm that Docker is installed correctly, open a PowerShell or Linux terminal and run the following command:
docker --version
If Docker is installed, you should see the version of Docker displayed, something like:
Docker version 24.0.5, build 55767e6
You can also test Docker by running a simple container. For example:
docker run hello-world
This command pulls the hello-world
image from Docker Hub and runs it as a container. If everything is set up correctly, you'll see a message that Docker is installed and working.
Step 4: Explore Docker Desktop Features
Docker Desktop has a user-friendly interface that allows you to manage images, containers, volumes, and more.
- Open Docker Desktop.
- You’ll see several tabs for Containers/Apps, Images, Volumes, and Dev Environments.
- You can start, stop, or delete containers and images from the interface.
Step 5: Install Docker Compose (Optional)
Docker Compose is a tool for defining and running multi-container Docker applications. It usually comes pre-installed with Docker Desktop, but you can verify the installation by running:
docker-compose --version
If it’s not installed, you can download it separately.
Step 6: Update Docker Desktop (Optional)
Docker Desktop frequently releases updates to improve stability and add new features. To keep your Docker installation up-to-date:
- Open Docker Desktop.
- Click on the gear icon (Settings).
- Under General, check Automatically check for updates.
Troubleshooting Common Issues
- Error: Docker requires WSL 2 to be installed: Make sure you’ve followed the steps to install and set WSL 2 as the default version.
- Error: Cannot connect to the Docker daemon: Restart Docker Desktop and check your WSL 2 configuration.
- Performance issues: Allocate more resources (CPU, Memory) to Docker under Settings > Resources.
Conclusion
By following this guide, you’ve installed Docker on Windows, configured it to use WSL 2, and verified that everything works. Docker enables you to run containers locally, making it easier to manage and deploy applications. Now you’re ready to start exploring Docker’s powerful features and build containerized applications with ease!