Install Docker on your Windows machine without installing Docker Desktop | by Tomáš Fry Pramuka | Medium

Source: How to install Docker on your Windows machine without installing Docker Desktop | by Tomáš Fry Pramuka | Medium

4 min read

Feb 16, 2024

Cartoon-style image of a whale and a shipping container. The whale should be whimsical and friendly, symbolizing Docker, and the shipping container. Generated by ChatGPT.

Docker and containers offer a wonderful life without installing numerous SDKs and frameworks on your machine — all just at your fingertips. All you need to do is to install Docker on your machine! But wait — what’s that lurking around the corner? A license agreement, you say? Let’s take a closer look.

Commercial use of Docker Desktop at a company of more than 250 employees OR more than $10 million in annual revenue requires a paid subscription (Pro, Team, or Business).

(See https://docs.docker.com/subscription/desktop-license/ for the full license agreement.)

If you are starting with containerization in your organization or your SaaS start-up with 10+ million in ARR, your best option is to use Docker without Docker Desktop.

To help you get started, I’ve prepared a short guide for setting up your Windows machine to locally create and debug images based on both Windows and Ubuntu.

Docker for Windows containers

Installing Docker on Windows is pretty straightforward. Install Chocolatey as a prerequisite and use these commands:

choco install docker-engine
choco install docker-cli

# Start docker daemon
start-service docker

Verify that everything is set up correctly by running this command:

docker run hello-world

If you get the ‘The request is not supported’ error like this:

hcsshim::CreateComputeSystem 27b5c80932aef84e743fe88bf023bd6e1cea1bbf25b0ab8875c8af701e3282b7: The request is not supported.

you need to enable Containers Windows feature.

Enabled Containers Windows feature.

That’s it! We are now ready to create and test Windows-based Docker images locally. Easy, right? Let’s step up and install Docker in Ubuntu running on the WSL to also be able to work with Linux-based images.

Docker for Linux containers

First, we need to enable WSL2 on our Windows machine and install Ubuntu (elevated permissions required):

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
wsl --set-default-version 2
wsl --install -d Ubuntu #or chooose different Linux submodule in this step

If the installation is successful, you will see an open terminal in Ubuntu. Follow the steps below to install Docker on Ubuntu. Note that installation steps may vary between distributions, primarily due to different package managers than apt-get installed on your distribution.

sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl gnupg lsb-release

# GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 

# Use stable repository for Docker
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Add user to docker group
sudo groupadd docker
sudo usermod -aG docker $USER #log out and log in again OR use the following command
newgrp docker

# Check that installation was successful
sudo service docker start
docker run hello-world

Now, you can run Docker in your Ubuntu instance within WSL. To reconnect to Ubuntu, use the wsl -d Ubuntu command. If you want to interact with Docker running in your Ubuntu distribution, run wsl docker images. This command will display all the Docker images in your default Linux distribution set within WSL.

Troubleshooting

Unfortunately, you might encounter some problems when you start working with Docker and images. I’ve selected a few issues I encountered while putting this guide together, along with their solutions.

apt-get update fails to fetch files, “Temporary failure resolving …” error

A temporary fix is to run this command in Ubuntu to add a known DNS server to your system:

echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf > /dev/null

For a permanent solution use:

sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
sudo bash -c 'echo "[network]" > /etc/wsl.conf'
sudo bash -c 'echo "generateResolvConf = false" >> /etc/wsl.conf'
sudo chattr +i /etc/resolv.conf

ERROR: failed to solve: XXX: failed to do request: Head “https://registry-1.docker.io/v2/library/XXX”: dial tcp: lookup registry-1.docker.io on 172.28.112.1:53: read udp 172.28.115.162:38680->172.28.112.1:53: i/o timeout

Use the fix above, it is the same problem with the same fix to resolve it.

permission denied while trying to connect to the Docker daemon socket at … connect: permission denied

This error should already be resolved by following the step-by-step guide. The problem arises if the user has not logged in again after being added to the docker group, or if the following command has not been executed:

newgrp docker

“Could not resolve host: download.docker.com” while installing docker CE

We need to modify the curl command to explicitly force curl to use IPv4, ensuring the URL is resolved correctly:

# GPG key
curl -4fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

“The request is not supported” error while running docker commands

This error is addressed in the guide — resolve it by enabling the ‘Containers’ feature in Windows.

Leave a Reply

The maximum upload file size: 500 MB. You can upload: image, audio, video, document, spreadsheet, interactive, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here