Wu Jiayi

Dev containers

devcontainersvscodeproductivity

“Works on my machine”

I worked on a project on and off for a few years. One day, a new colleague joined the project and tried to set it up on his machine. The project is pretty complex to set up, requiring the installation of various software. I thought the readme is very detail and up-to-date, but it turned out it wasn’t. The colleague spent over a day fixing some weird errors that I couldn’t reproduce on my machine. I did the setup a few years back when I onboarded to the project, and it worked, so I never changed the settings again. I hope there is a way to make the setup consistent and easy for everyone.

What is devcontainer?

The Visual Studio Code Remote - Containers extension allows you to use a Docker container as a full-featured development environment. This helps ensure a consistent environment across developer machines and makes it easy for new team members and contributors to get up and running.

Do I have to use vscode?

Yes, I know what you’re thinking, but trust me, once you appreciate the benefits of devcontainers, switching to vscode will be a no-brainer. vscode is the best IDE that supports devcontainers.

System requirements

Demo

I created a GoLang project to demonstrate the use of devcontainers.

It can be a bit slow to start the container for the first time, but the subsequent start up should be much faster because of caching. Once the devcontainer has started, it already includes all the software (e.g., Python, Go, pre-commit, etc.) and vscode extensions for you. To try it out, launch the terminal in vscode and try a few exercises:

This is great! With the devcontainer configuration, everyone working on the project will have the exact same setup. No more it works on my machine dramas.