Member-only story
Optimizing VS Code Dev Containers on Windows
Improving disk performance in your dev container environment with named volumes
What Are VS Code Dev Containers?
Visual Studio Code Remote Containers is a VS Code extension that solves one of software engineering’s oldest problems: “But it works on my machine.” Dev containers also allow you to close the gap between your development and production environments, making it much easier to debug production issues.
As long as you have Docker and VS Code installed on your machine, you can easily configure your projects with a Dockerfile and a devcontainer.json
file. With the dev container extension, VS Code can then open your project workspace in an isolated environment with all the dependencies defined in the Dockerfile. This way, anyone who clones the repository will be able to spin up exactly the same development environment — regardless of what host operating system they use.
Performance Issues on Windows
Unfortunately, it turns out running dev containers on Windows has some performance issues. In some cases, I couldn’t even run npm install
to install the necessary package dependencies for my projects. Docker would just hang. For the projects that had fewer dependencies, installing the dependencies still took a lot longer than when I was developing on my MacBook Pro or even booting up Linux on the same PC. This definitely didn’t appear to be a hardware issue.
It turns out this actually seems to be a well-known issue when running dev containers on Windows, as the VS Code documentation provides tips on improving container disk performance. It specifically mentions node_module
and points to the use of named volumes to solve the issue.
Here’s what they suggest you include in the devcontainer.json
file:
This does indeed solve the issue. Here is one of my smaller projects before and after setting up a named volume: