Skip to content

Instantly share code, notes, and snippets.

@Cube707
Last active June 6, 2024 10:03
Show Gist options
  • Save Cube707/1aa9e664c010b16f592e5f729da7c357 to your computer and use it in GitHub Desktop.
Save Cube707/1aa9e664c010b16f592e5f729da7c357 to your computer and use it in GitHub Desktop.
How to install native docker on windows

Why?

You can of course just install Docker Desktop, but there are situation where you don't want / can't use it.

So its good to know that you actually don't need to and can isntead intall only the docker binaries. The only drawback is that it only allows you to use Windows images with now option to switch to linux based images.

The easy option: Installing via winget

As of docker-cli >= v24.0.2 you can also install via the winget tool. That makes it significantly easier, but gives you less contoll. So I am leaving the rest up here.

winget install --id Docker.DockerCli

Installing manually

Note The following assuemes that you are working in a PowerShell terminal sesstion with administrative rights.

Prerequisits

You need Hyper-V to use docker. Run this to ensure you have it:

Enable-WindowsOptionalFeature -Online -FeatureName containers –All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V –All

You might need to resart the PC.

Get the binaries

Docker publishes the binaries, you just need to know where to find them.

find the most recent version

Run this handy command to get a list of avalable files:

$url = 'https://download.docker.com/win/static/stable/x86_64/'
(curl $url).Links | ForEach-Object {$url + $_.href}

select the version you want to get from the list.

download the binaries

First create the Directory Docker should live in (don't change into it!):

mkdir docker

Than download the ZIP-archive and extract its content:

curl.exe -o docker.zip -L 'SELECTED URL'
Expand-Archive docker.zip -DestinationPath .
rm docker.zip

Installation

For the following steps, switch to a powershell with administrative rights.

Adding to PATH

You probably want access to the docker command from anywhere, so add the new folder to the enviroment PATH:

[Environment]::SetEnvironmentVariable("Path", "$($env:path);$(Resolve-Path Docker)", [System.EnvironmentVariableTarget]::Machine)
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")

Run dockerd as a service

You can manyally start dockerd whenever you need it, but it is more convenient if its just allways running. So you can register it as a service and have that running allways.

As docker uses a named pipe on windows, you need to grant access to this for all useres that require it. This can be only your usernam, a custom group you create, or simply all users. Pass this in as the --group argument (even if its just a username). I am going to allow all users:

dockerd --register-service --group=Users
Start-Service docker

Note
Default group names depend on you language setting, so Users will only work on systems that where set up using the english language. So adjust acordingly.

Test if it works

Lets run the docker 'hello world':

docker run hello-world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment