Skip to content

Instantly share code, notes, and snippets.

@psiphi75
Last active January 24, 2026 22:18
Show Gist options
  • Select an option

  • Save psiphi75/f314c79c9f5ccfd8144f738cea92515b to your computer and use it in GitHub Desktop.

Select an option

Save psiphi75/f314c79c9f5ccfd8144f738cea92515b to your computer and use it in GitHub Desktop.
A Devcontainer config that just works

A Devcontainer config that just works

A devcontainer configuration that just works. It uses Ubuntu 24.04 and uses the ubuntu user inside the container. The ubuntu user will have the same userid as the host user (in most cases) so the file permissions don't get warped.

Setup

The devcontainer.json and Dockerfile files need to go into a .devcontainer/ folder, like so:

.devcontainer/Dockerfile
.devcontainer/devcontainer.json
{
"name": "Just-Works-TM Devcontainer",
"build": {
"dockerfile": "Dockerfile"
},
"containerEnv": {
"HOST_OS": "${localEnv:OS}",
"HOST_USERNAME": "${env:USERNAME}"
},
"customizations": {
"vscode": {
// Install relevant extensions in the dev container
"extensions": [
]
}
},
// Ensure the workspace is mounted correctly
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
"workspaceFolder": "/workspace",
// Run commands after the container is created
"postAttachCommand": ""
}
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
git \
build-essential \
locales \
sudo \
&& rm -rf /var/lib/apt/lists/*
# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8
# Let's git trust our own repo.
RUN git config --global --add safe.directory /workspace
# Set up the non-root user.
ARG USERNAME=ubuntu
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
USER $USERNAME
ENV ENV=~/.profile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment