VSCode Dev Container - Configurations
Published on

VSCode Dev Container - Configurations

Authors

All the example code provided can be directly used in the devcontainer.json file, you only need to make sure that you place the configurations in the correct place. So please count the number of curly braces {} before placing the configurations.

Providing Custom name for Dev Container that gets created

Normally dev containers get some random names but incase you want to provide a name for your dev container. You can do so by updating your devcontainer.json file with runArgs argument.

{
  "build": {
    "dockerfile": "Dockerfile"
  },
  "customizations": {
    "vscode": {
      "extensions": []
    }
  },
  "runArgs": ["--name=ui-dev"]
}

Using Dockerfile for Dev Container

You can use a Dockerfile to create a dev container. You can specify the path of the Dockerfile in the devcontainer.json file.

{
  "build": {
    "dockerfile": "Dockerfile"
  }
}

Using Extensions in Dev Container

You can specify the extensions that you want to install in the dev container in the devcontainer.json file.

{
  "customizations": {
    "vscode": {
      "extensions": [
        "github.vscode-github-actions",
        "GitHub.copilot",
        "ms-vscode.wordcount"
      ]
    }
  }
}

Attaching volumes to Dev Container

You can attach volumes, where you want to share the data between the host and the dev container. You can specify the volumes in the devcontainer.json file. Here I'm sharing the ~/.ssh directory with the dev container.

{
  "mounts": ["source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind"]
}

Attaching Network to Dev Container

You can attach a network to the dev container. You can specify the network in the devcontainer.json file.

{
  "runArgs": ["--network=custom-network"]
}

Source Image for Dev Container

You can specify the source image for the dev container. You can specify the source image in the devcontainer.json file.

{
  "image": "ubuntu:22.04"
}

But as I make use of Dockerfile for creating the dev container, I don't use the image argument in the devcontainer.json file so we need to put the source image in the Dockerfile.

FROM ubuntu:22.04

# Install additional packages