VSCode DevContainer setup for C/C++ programmers

This article delves into getting a VS Code DevContainer Development environment based setup for early C/C++ programmer. The environment runs on Debian, and hence is a good place to start for all School / College students too.

As part of my investigations for my college teaching environments, I was in a situation where I needed to teach C++. And, as some of my readers know, I am compulsively obsesses with not installing any compiler, or programming environment, on my local machine. It has to run in a throwaway-able environment.

So, I looked at the default DevContainer setup that Microsoft ships as part of their images. The environment created a 2GB image on my machine. That was really not something I like working with. So, here are the things you to be more efficient, and nimble.


This article assumes you have the following already installed and configured:

Getting started

Create an empty project folder in a location of your choice on the machine. And then:

mkdir .devcontainer

This will create a .devcontainer folder inside that. The below files will go inside this folder.

The Dockerfile

I used the following Dockerfile for the environment:

FROM debian:stable-slim

RUN apt-get update \
    && apt-get install -y git g++ gcc make gdb \
    && apt-get clean


CMD ["sleep infinity"]

This gets us in a good place. It has support for the tools mentioned in the install line, and generates an image the size of approximately 820MB. A far cry from the 2GB+ from the Microsoft Container repository. Plus, I have control over the linux version, and more.

The DevContainer

The Dockerfile is never enough. It has to be supplemented with an appropriate devcontainer.json to be effective. So, here is the my version of that file.

    "name": "cpp-dev-container",
    "build": {
        "dockerfile": "Dockerfile"
    "customizations": {
        "vscode": {
            "settings": {
                "remote.downloadExtensionsLocally": true,
                "telemetry.enableTelemetry": false,
                "extensions.ignoreRecommendations": false,
                "workbench.remoteIndicator.showExtensionRecommendations": false
            "extensions": [

There you go. Now you are ready to Ctrl+P or Cmd+P and Reopen in Container .

When you open the container, there is an extension called CompileAndRun that will allow you to run the current C/C++ file using the default settings. You can also set the breakpoints.

Have fun C++ing

About the Author

The Author, Navneet Karnani, began coding with Java in 1997 and has been a dedicated enthusiast ever since. He strongly believes in the "Keep It Simple and Stupid" principle, incorporating this design philosophy into all the products he has developed.

Navneet works as a freelancer and is available for contracts, mentoring, and advisory roles related to technology and its application in software product development.

Additionally, Navneet serves as a visiting faculty member at FLAME University.

Driven software engineer (Java since 1997) with a hands-on passion for building impactful tech products. Possesses over 25 years of experience crafting solutions to complex business and technical challenges.

Did you find this article valuable?

Support MandrakeTech Blog by becoming a sponsor. Any amount is appreciated!