The Power of Dev Containers and GitHub Codespaces

From Local Dev to Cloud Ready: Portable Environments with Dev Containers & Codespaces

Chris Ayers

Chris Ayers

Senior Risk SRE
Azure CXP AzRel
Microsoft

BlueSky: @chris-ayers.com
LinkedIn: - chris-l-ayers
Blog: https://chris-ayers.com/
GitHub: Codebytes
Mastodon: @Chrisayers@hachyderm.io
Twitter: @Chris_L_Ayers

Agenda

  • Prerequisites
  • What Are Dev Containers?
  • Why Use Dev Containers?
  • How Dev Containers Work
  • How to Build a Dev Container
  • Templates, Features, Customization
  • GitHub Codespaces
  • Demo

Prerequisites

DevContainers

  • VSCode
    • Dev Containers Extension
    • GitHub Codespaces Extension
  • IntelliJ IDEA

Docker

  • Docker installed locally
  • Remote Docker host (optional for remote container execution)
  • Other Docker compliant CLIs, installed locally or remotely

GitHub Codespaces Requirement

  • GitHub Account
  • GitHub Codespaces

What are Dev Containers?

  • Environments that run in a container
  • Containers that let you open or mount any folder and still use VS Code UI and tooling
  • Places to run Apps, Tools, or Runtimes needed for a project or codebase
  • Containers.dev - An open specification for enriching containers with development specific content and settings.

Why use Dev Containers?

  • Onboard new People
  • Use consistent tooling
  • Use consistent versions
  • Reduce System Conflicts
  • Perform Startup Tasks
    Improve security via isolation

Inner and Outer Loops

How Dev Containers Work

Dev Containers

Your editor talks to a containerized environment with all the dependencies, so your local system stays clean.

Where do Dev Containers Live?

devcontainer folder

Multiple Dev Container Configurations

Tooling supports multiple devcontainers.
Each one should be in its own subdirectory at:

.devcontainer/SUBDIRECTORY/devcontainer.json.

How do you build a Dev Container?

From the Command Pallet

Add Dev Container files

Which Dev Container do I Pick?

Add Options

Templates

Full List: https://containers.dev/templates

  • Base (Alpine, Debian, Ubuntu)
  • Language Based (C#, C++, Java, Go, Node, Python, Rust, Ruby, PHP)
  • Tool Focused (Markdown, Kubernetes, Docker, Jekyll)

Customizations

  • Features - Install tools into the container image.
  • Extensions - Install extensions for the editor inside the container.
  • Settings - Configure the editor settings inside the container.
  • Startup Tasks - Run commands when the container starts.
  • Networking - Port Forwarding - Expose ports to the host.

Features

Full list here: https://containers.dev/features

  • CLIs (azure, gh, gcp, aws)
  • Tools (Terraform, kubernetes...)
  • Runtimes (Node, Python, Go, Java, .NET, PHP, Ruby, Rust, C/C++, C#)

Configuration Loop

Configuration Loop

GitHub Codespaces

  • Don't need to worry about Docker Desktop
  • VSCode, IntelliJ, Browser
  • From 2 cores up to 16 cores w/ 64GB of RAM
  • Default universal DevContainers
  • Codespaces only offers Linux as the OS and x86_64 as the Architecture
  • Spin up secure, disposable environments for PR reviews, testing, or onboarding.

GitHub Codespaces Architecture

GitHub Codespace templates

https://github.com/codespaces/templates

DEMO TIME

Resources