published 2021-12-05
I use Docker with Compose for local development. I work on a Windows system, use VS Code, and develop in both the Windows CMD terminal and under WSL 2.
Docker now has a policy of requiring developers working in an organization with more than a certain number of employees (250) or annual revenue ($10M) to pay for a subscription.
I work (a) in large-scale enterprise organizations, but (b) on small independent teams within those organizations. Because of (a), I don't qualify for the free Docker Desktop license in these contexts. But, because of (b), I am being put in a position to pay for my own subscription and then submit an expense report. Maybe that's what I should do, but I don't want to.
Meanwhile, I've noticed that I don't really need or use the features of Docker Desktop: The commandline client and system daemon are enough for me. So that brings me to a couple of solutions.
Install WSL 2 - see https://docs.microsoft.com/en-us/windows/wsl/install
tldr; Run Powershell as an administrator:
wsl --install
wsl --update
Install Ubuntu
In a CMD or Powershell terminal:
wsl --install -d Ubuntu
wsl --set-default Ubuntu
wsl --set-version Ubuntu 2
Install Docker - see https://docs.docker.com/engine/install/ubuntu/
tldr; Open an Ubuntu terminal:
sudo apt-get update \
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
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
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
This is pretty standard for installing Docker on Linux. Digital Ocean also has a nice blog post covering the process: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04
Startup Docker automatically - see https://blog.nillsf.com/index.php/2020/06/29/how-to-automatically-start-the-docker-daemon-on-wsl2/
Since WSL 2 doesn't use systemd, the dockerd
doesn't start automatically on system boot. So instead, you can just start it when you log into Ubuntu by adding the following to your ~/.bashrc
file:
# Start Docker daemon automatically when logging in if not running.
DOCKER_RUNNING=$(ps aux | grep dockerd | grep -v grep)
if [ -z "$DOCKER_RUNNING" ]; then
sudo dockerd > /dev/null 2>&1 &
disown
fi
There might be less "hacky" ways to operate, but it works. When you log in again, you can:
$ docker --version
Docker version 20.10.11, build dea9396
(If you need to daemonize docker at the system level, you'll probably dig into creating a Windows service. I don't need that for my use case, but I'm sure it wouldn't be too difficult for the determined: See https://docs.microsoft.com/en-us/archive/msdn-magazine/2016/may/windows-powershell-writing-windows-services-in-powershell.)
Install scoop: See https://scoop.sh/
Install Docker with scoop.
Open a CMD or Powershell terminal:
> scoop install docker
That's it.
> docker --version
Docker version 19.03.1, build 74b1e89e8a
I've just done this on my local system, so I don't yet know how well it will work in daily use. However, since I typically have an open terminal with docker compose up
running for the current app, I expect that this will work just fine with either installed versions of Docker (Windows via scoop or Ubuntu).