Search code examples
vscode-remote

Remote-Containers: Can I create a standard default devcontainer.json?


So I have one local container that I want to use for the Remote-Containers support. But I can't seem to create a single default devcontainer.json to utilize this. Am I correct that it's a file per project or repository?


Solution

  • The idea is to have the devcontainer.json version-controlled in the repository, so that anyone checking the repo out can use the standard container configuration.

    If you're cloning a 3rd party repo which you want to run locally in a container, you will need to create the config file yourself if it's missing.

    If you find yourself in need of the same devcontainer config over and over again, consider submitting a pull request at https://github.com/microsoft/vscode-dev-containers.

    Having said that, it should be straightforward to create the config. If you're going to use an existing Docker image it is as simple as creating a single file:

    .devcontainer/devcontainer.json

    {
        "image": "local image name or remote url"
    }
    

    If you have a Dockerfile you want to build from, again it's a single option:

    {
        "dockerFile": "Dockerfile"
    }
    

    That's all you need. Fire Reopen in container VS Code command and you're set.

    If you want to configure port mapping, or change the user you will need to add that of course, but anyway it will be quite minimal.