Did someone say Container?

vscode has some rather nice docker integrations. There are some that will allow you to manage your containers form inside the editor, which may be interesting to control databases to connect to, but today we are interested in another feature.

Devcontainer

The other way to use containers in development workflows is about the actual build env. Since we may be on a different environment with our production machines than our development machines, or just don’t want to clutter the dev’s machine, we may not be able to install all dependencies on the host environment.

With dev containers, this is easy. We simply split the development host from the development environment. There are a lot of tools for that, but the ones that work in the most generic way are certainly containers. In thi scase, we use the docker container runtime, because it already provides great tooling integration, and we don’t have to worry as much ourselves.

vscode has several remote development extensions. We are interested in the container variant. While we can do similar stuff with the ssh variant, it does not support some of the nicest features.

The Setup

  • Install the extension.
  • Make sure you have docker installed
  • Open the folder with your project

You should also take a look at the container remote extension’s settings. The in-container vscode will start without your extensions. I f you have quality of life extensions (like git lens, vim etc.) it makes sense to add them to your default container extension list.

Getting the Container Definition

After you have gone through the setup steps, simply press [F1] and pick “Add Development Container Configuration Files” to add the initial definition. vscode will guide you through some initial configurations with questions about what you want to base your container on.

To actually open the project in a container, press [Ctrl]+[Alt]+p to get the command palette, and pick “Rebuild and Reopen in Container”. You will have to slightly tinker with your files, to get them configured the way you ned them to.

E.g. for my projects I need to also install the native dependencies (meson, compiler…) and add the C++ toolkit and mesonbuild.mesonbuild to the extensions to be installed in the container vscode.

Start Developing

And that’s it. You got your development environment set up. Start doing great things. Note that the extension also does some magic to set up your git and ssh configurations. IFF they are somewhat stanadard and you use ssh-agent. This allows you to fully manage your interaction with code from withing the container, as it will be able push/pull/rebase your code.