Running docker-compose against WSL2

Just adding a quick note for myself here. I wanted to run against docker host on WSL2 and docker compose connects to DockerDesktopVM instance by default (the full virtual machine). What I wanted to try is to run Docker Compose experience without the virtual machine utilizing the new WSL2 capabilities.

Scott Hanselman has a good write-up about this feature.

Prequisities

  • Windows 10 insider build from the fast ring (at the time of writing), build 18932 or newer
  • Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
  • Install Ubuntu 18.04 from Windows Store, ensure it has the correct WSL version
    • wsl --set-version Ubuntu-18.04 2
  • To make life easier, make the new version default
    • wsl --set-default-version 2
  • Install Docker Desktop WSL 2 Technical Preview

Run docker-compose targeting the Linux WSL2 docker host

The key is to use the -H parameter, when you are hosting both the Virtual Machine and lightweight WSL2 version.

docker-compose -H "npipe:////./pipe/docker_wsl" up -d

And now my containers managed by compose are running under the lightweight WSL2 model. The full-blown Docker virtual machine can be shutdown while using in this WSL2 mode.

If you want permanently target the WSL2 engine, you can also set environment variable DOCKER_HOST to point to this npipe protocol address.

Comments

Popular posts from this blog

Optimizing Jint part 6: DictionarySlim is coming to town

Optimizing Jint part 2: Tools of the trade