How to Standardize Dev Environments with DevContainers.

Learn how to standardize dev environments using DevContainers in GitHub Codespaces. Improve team workflows, reduce onboarding time, and boost productivity!

Introduction

Every developer has faced the “works on my machine” issue at some point—whether due to missing dependencies, conflicting versions, or onboarding delays. DevContainers solve this problem by providing a pre-configured, reproducible, and standardized environment that works seamlessly with GitHub Codespaces and VS Code.

In this guide, we’ll explore how you can:

  • Share DevContainers across multiple repositories.
  • Standardize development environments for your team.
  • Leverage GitHub Codespaces for cloud-based development.

By the end of this post, you’ll have a reusable DevContainer setup that ensures consistency across all your GitHub repositories.


What Are DevContainers?

DevContainers, short for Development Containers, are a feature in VS Code and GitHub Codespaces that allow you to:

  • Define a fully configured development environment using a .devcontainer directory.
  • Include dependencies, SDKs, and extensions in a reproducible way.
  • Share the environment across teams and repositories.

A typical DevContainer setup includes:

  • devcontainer.json – The configuration file specifying extensions, ports, and settings.
  • Dockerfile (optional) – A customized container with all necessary dependencies.
  • VS Code Extensions – Preinstalled tools for a smooth developer experience.

Why Standardize Dev Environments with DevContainers?

🚀 Benefits for Teams:

Consistent Environments – Everyone works in the same setup, reducing “works on my machine” issues.
Instant Onboarding – New team members can start coding immediately, no manual setup required.
Cross-Repository Usability – Use the same environment across multiple projects.
Cloud-Based Development – With GitHub Codespaces, you can code from anywhere without installing dependencies locally.


Setting Up a Reusable DevContainer

Instead of adding a .devcontainer folder in every repository, you can create a centralized DevContainer that your team can use across multiple projects.

1️⃣ Create a Centralized DevContainer Repository

  1. Create a new GitHub repository (e.g., org/devcontainers).
  2. Add a .devcontainer directory with the following files:

📌 devcontainer.json

 1{
 2  "name": "Standard Dev Environment",
 3  "image": "mcr.microsoft.com/devcontainers/universal:latest",
 4  "features": {
 5    "terraform": "latest",
 6    "azure-cli": "latest"
 7  },
 8  "extensions": [
 9    "hashicorp.terraform",
10    "ms-azuretools.vscode-docker"
11  ],
12  "settings": {
13    "editor.formatOnSave": true
14  }
15}

📌 Dockerfile (optional, for custom environments)

 1# Use Microsoft's universal DevContainer base image
 2FROM mcr.microsoft.com/devcontainers/universal:latest
 3
 4# Install Terraform
 5RUN curl -fsSL https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg \
 6    && echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/hashicorp.list \
 7    && apt-get update && apt-get install -y terraform
 8
 9# Set work directory and default shell
10WORKDIR /workspace
11
12# Start the container with an interactive shell
13CMD ["/bin/bash"]

📌 extensions.json

1{
2  "recommendations": [
3    "hashicorp.terraform",
4    "ms-azuretools.vscode-docker"
5  ]
6}

2️⃣ Using the Shared DevContainer in Any Repository

Developers can apply the shared DevContainer to any repo without copying files manually. Here’s how:

Option 1: Clone and Use the DevContainer

In a new repo:

1# Clone the central DevContainer repository
2git clone https://github.com/org/devcontainers
3
4# Copy the shared DevContainer setup into a new project
5cp -r devcontainers/.devcontainer my-project/

Developers can now open the repo in VS Code and click “Reopen in Container”.

Option 2: Automate DevContainer Usage with GitHub Codespaces

1.	Set a Default DevContainer for Your Organization:
•	Go to GitHub Organization Settings > Codespaces > Default Configuration.
•	Specify the central DevContainer repository (org/devcontainers).
2.	Now, any repository without a .devcontainer/ will automatically use this configuration! 🚀

Best Practices for Sharing DevContainers

✅ Optimize for Performance: Avoid installing unnecessary tools to keep the container lightweight.
✅ Use Versioned Base Images: Specify exact versions in devcontainer.json or Dockerfile to prevent unexpected changes.
✅ Provide Clear Documentation:

  • Add a README.md explaining the DevContainer setup.
  • Include a list of installed dependencies and extensions.

✅ Automate Updates:

  • Use GitHub Actions to automatically rebuild and test DevContainers.
  • Add dependency update checks for Terraform, Azure CLI, and VS Code extensions.

📢 Frequently Asked Questions (FAQs)

❓ What is a DevContainer in GitHub?

A DevContainer is a pre-configured development environment that ensures all developers work in the same setup. It runs inside VS Code and GitHub Codespaces, providing a consistent, reproducible environment with all required tools, dependencies, and extensions pre-installed.

❓ How do I create a shared DevContainer for my team?

You can create a centralized DevContainer repository, define your development environment in devcontainer.json, and reference it in multiple repositories. This ensures all projects use a consistent and pre-configured setup.

❓ Can I use DevContainers with GitHub Codespaces?

Yes! GitHub Codespaces fully supports DevContainers, allowing developers to instantly spin up cloud-based environments.

❓ What are the benefits of using DevContainers?

✅ Ensures consistent development environments across teams.
✅ Instant onboarding—no need to install dependencies manually.
✅ Works locally in VS Code or remotely in GitHub Codespaces.
✅ Reduces “works on my machine” problems.

❓ Can DevContainers be used with GitHub Actions?

Yes! You can integrate DevContainers into GitHub Actions workflows for CI/CD automation, running tests, and validating infrastructure changes.

❓ How do I automate updates in a DevContainer?

To keep your DevContainers updated: 1. Use versioned images in devcontainer.json or Dockerfile. 2. Automate dependency updates using GitHub Actions. 3. Regularly rebuild and test containers to prevent drift.

Conclusion

By using DevContainers, you can standardize development environments, reduce onboarding friction, and ensure consistency across teams. When combined with GitHub Codespaces, DevContainers enable seamless cloud-based development.

💡 Next Steps:

  • ✅ Create a DevContainer template repository for your team.
  • ✅ Configure GitHub Codespaces to use it as a default.
  • ✅ Encourage adoption across your engineering team.

Want to see a step-by-step tutorial on integrating DevContainers with Terraform or AKS? Let me know in the comments! 🚀