How to use Docker without Docker Desktop on Windows 10 or 11

Published:

Why can't you just use Docker Desktop to install Docker?

The easiest way to start using Docker on Windows is to use Docker Desktop. The software is free to use for personal use, but if you are using it professionally, you probably need to get a subscription to use it:

From Docker's FAQ:

Who’s required to pay for Docker subscription plans?

[...] (a) The use of Docker Desktop without a paid Subscription, is further restricted (i) to your use for a non-commercial open source project and/or (ii) use in a commercial undertaking with fewer than 250 employees and less than US $10,000,000 (or equivalent local currency) in annual revenue. Government Entities shall not use Docker Desktop or access other Entitlements of the Service without purchasing a Subscription

https://www.docker.com/pricing/faq/

What does Docker Desktop do? Can Docker run by itself?

You can run Docker by itself without Docker Desktop. Docker Desktop is just a GUI wrapped around the Docker CLI tools, and a helper to install the tools you need.

If you are using Docker on Windows, what is happening behind the scenes, is that Docker is running inside WSL (Windows Subsystem for Linux) in a Linux distro and then the command line is set up to "forward" your Docker commands to WSL.

This guide will show you how to set this up manually.

Install WSL and Ubuntu

Follow Microsoft's guide to install WSL: https://learn.microsoft.com/en-us/windows/wsl/install

Afterwards, you should see something like this in PowerShell. You might see more than one distro in this list, but for this guide I assume you have a version of Ubuntu marked as (Default).

PS C:\> wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-24.04 (Default)
PS C:\> wsl --version
WSL version: 2.4.13.0

💡It is important that you have WSL version 2 or above.

If you want a clean install of Ubuntu before you install Docker, you can re-install it:

PS C:\> wsl --unregister Ubuntu-24.04
PS C:\> wsl --install Ubuntu-24.04
Distribution successfully installed.

Install Docker

The following are the necessary steps taken from Docker's guide to install Docker on Ubuntu: https://docs.docker.com/engine/install/ubuntu/

Refer to their guide if you need more details than I provide here. I found I could skip a few of their steps.

Open an Ubuntu terminal

In Windows Terminal you probably have a new option to open a tab with Ubuntu directly.

Windows Terminal's new tab options with PowerShell and Ubuntu

Otherwise just open PowerShell and run wsl to open a terminal in your default Linux distro.

PS C:\> wsl
bjarte@MyComputer:/mnt/c$

Add Docker's package repository

Add Docker's official GPG key:

$ 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.asc

Add the 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 "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update

Install Docker and related packages

$ sudo apt-get install docker-ce docker-ce-cli \
    containerd.io docker-buildx-plugin \
    docker-compose-plugin

Check that Docker and Docker Compose are installed and working:

$ docker --version
Docker version 28.0.4, build b8034c0
$ docker compose version
Docker Compose version v2.34.0

Make sure your Ubuntu user can run Docker without sudo. You might get the following:

$ docker ps
permission denied while trying to connect to the Docker daemon

These steps allow you to run it without sudo:

$ sudo groupadd docker # Create group docker
$ sudo usermod -aG docker $USER # Add your user to the docker group
$ newgrp docker # Log in to the new docker group

Check that you can now run Docker without sudo:

$ docker run hello-world
Hello from Docker!

You can now run Docker directly from the PowerShell terminal using the wsl command:

PS C:\> wsl docker --version
Docker version 28.0.4, build b8034c0

Set up aliases to pretend you're running Docker in PowerShell

To avoid typing wsl every time you use Docker (like the setup Docker Desktop gives you), add aliases to your PowerShell profile.

Edit your profile in Notepad:

PS C:\> notepad $profile

Add these aliases:

Function DockerFromWindows { 
  wsl docker $args 
}
Function DockerComposeFromWindows { 
  wsl docker-compose $args 
}
Set-Alias -Name docker -Value DockerFromWindows
Set-Alias -Name docker-compose -Value DockerComposeFromWindows 

You're done! 🎉

Open a new PowerShell terminal to reload your profile settings, and voila!

PS C:\> docker run hello-world
Hello from Docker!

Categories: Docker Windows

Comments