Skip to content

Instantly share code, notes, and snippets.

@CodeMan99
Last active August 5, 2025 04:13
Show Gist options
  • Save CodeMan99/7dcc891e2c73ec0dfbedf6feb7f1113f to your computer and use it in GitHub Desktop.
Save CodeMan99/7dcc891e2c73ec0dfbedf6feb7f1113f to your computer and use it in GitHub Desktop.
A devcontainer example
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/debian
{
"name": "Debian",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"dockerfile": "Dockerfile"
},
// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash"
},
"extensions": [
"mads-hartmann.bash-ide-vscode",
"rogalmic.bash-debug"
]
}
},
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": false,
"installOhMyZsh": false,
"installOhMyZshConfig": false,
"username": "dave"
},
"ghcr.io/devcontainers/features/github-cli:1": {},
"./ysap/features/bats-core": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "dave"
}
FROM debian:bookworm-slim
RUN apt-get -y update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \
bash-builtins \
bind9-dnsutils \
binutils \
bsdextrautils \
ca-certificates \
coreutils \
curl \
diffutils \
dos2unix \
ed \
file \
findutils \
fzf \
inetutils-ping \
moreutils \
ripgrep \
tmux \
util-linux \
xxd \
&& rm -rf /var/lib/apt/lists/*
{
"name": "Bash Automated Testing System (By YSAP)",
"id": "bats-core",
"version": "0.0.1",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
#!/usr/bin/bash
#
# Our working directory is "/tmp/dev-container-features/bats-core_1". All files
# created in the working directory are cleaned up by the devcontainer build.
set -e
if [[ -z "$_REMOTE_USER_HOME" ]] && [[ -d "/home/${_REMOTE_USER}" ]]; then
_REMOTE_USER_HOME="/home/${_REMOTE_USER}"
fi
declare prefix="${_REMOTE_USER_HOME}/.local"
declare tarball_url="$(curl -fsS "https://api.github.com/repos/bats-core/bats-core/releases/latest" | jq -r .tarball_url)"
curl --location --output bats-core.tar.gz "$tarball_url"
tar --strip-components=1 -xzf bats-core.tar.gz
su $_REMOTE_USER -c "./install.sh "$prefix" "

Devcontainers

A reproducible development environment built on top of docker containers.

Documentation References

Example - Configuration Only

In a file named .devcontainer/devcontainer.json:

{
    // Give a name to the "workspace"
    "name": "Debian",
    
    // Reference any docker image, this is a pre-configured image from microsoft specifically for devcontainers
    "image": "mcr.microsoft.com/devcontainers/base:1-bookworm",
    
    // The default user for the workspace, most microsoft images include a user named "vscode"
    "remoteUser": "vscode"
}

Of course there are more options. Lifecycle hooks. Building an image. Using a compose project. Adding features. A customizations field to configure tools.

Customizations

This is honestly mostly for Microsoft and Github tools. Is that really a bad thing?

Features

Features are the meta configuration of devcontainers. Allowing you to mix / merge / share configuration across many projects. A feature can do everything a devcontainer can and has a well defined hook into the build system: install.sh.

Example - Multiple Files

Please read the rest of the files in this gist. This example explores some of the more advanced features of devcontainers.

  • Creating a custom user, this one is named "dave".
  • Install the Github CLI as a feature.
  • Creates a one-off feature for the bats-core project. This is NOT necessary. There's many ways to accomplish this.
  • Builds a custom image starting at debian:bookworm-slim.
  • If using vscode, installs extensions useful for bash editing.
  • If using vscode, sets the default profile of the terminal to bash.
.devcontainer/
├── devcontainer.json
├── Dockerfile
└── ysap
    └── features
        └── bats-core
            ├── devcontainer-feature.json
            └── install.sh

Note, because gists do not support directories, files are using double underscore as separators. That is .devcontainer__devcontainer.json means .devcontainer/devcontainer.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment