Choosing a Dev Container Base Image for GitHub Codespaces
A concise decision guide for picking a base image that balances startup speed, tooling, and size while staying within the 2 GB Codespaces limit.
07 Mar 2026, 18:18 UTC

Problem and Takeaway
When you create a GitHub Codespace, the underlying dev container must be pulled from a base image. If the image is too large, the Codespace may fail to start because it exceeds the 2 GB storage limit; if it is too small, you spend extra time installing runtimes and tools. The useful takeaway is to pick a base image that gives you the required language runtimes with minimal post‑creation work while keeping the download size comfortably under the limit.
Decision and Constraints
You need to decide which base image to reference in .devcontainer/devcontainer.json. The decision must satisfy these constraints:
- Support the languages/runtimes your project uses (e.g., Node .js, Python, Go).
- Keep the combined image size plus project files below the 2 GB Codespaces storage limit.
- Allow secrets and port forwarding as needed (all standard images support this).
- Minimize startup time and manual setup steps.
Comparison of Supported Options
| Option | Base Image | Typical Size | Pre‑installed Tools | Customization Effort |
|---|---|---|---|---|
| Default Ubuntu | mcr.microsoft.com/vscode/devcontainers/universal | ~1.2 GB | Git, Node, Python, Java, Go, C++ | Low (add missing tools via postCreateCommand) |
| Minimal Ubuntu | mcr.microsoft.com/vscode/devcontainers/base:ubuntu | ~300 MB | Git, basic shell | Medium (install runtimes and tools yourself) |
| Language‑specific (e.g., Python) | mcr.microsoft.com/vscode/devcontainers/python:3-11 | ~800 MB | Python, pip, virtualenv | Low for Python projects (add other tools if needed) |
| Custom Dockerfile | Any Docker Hub image (e.g., ubuntu:22.04) |
Variable | As defined in the Dockerfile | High (full control, but you maintain the file) |
Trade‑offs
The Default Ubuntu image gives the fastest startup for most polyglot projects because the common tools are already present, but its ~1.2 GB size can push you close to the storage ceiling when combined with a sizable codebase. The Minimal Ubuntu image reduces download time and storage footprint, yet you must install each runtime yourself, which adds to the postCreateCommand length and can increase the time it takes for a Codespace to become ready. Language‑specific images strike a middle ground: they provide the core toolchain for a given language with a modest size, lowering the amount of extra setup while staying well under the limit. A Custom Dockerfile offers complete control over the image contents, but each Codespace start triggers a build, increasing latency and requiring you to keep base images patched to avoid security risks.
Concrete Implementation
Below is a step‑by‑step example for a Python‑only project that chooses the language‑specific image.
- Create the devcontainer configuration folder if it does not exist:
mkdir -p .devcontainer
- Add
.devcontainer/devcontainer.jsonwith the following content (replacemy-python-appwith your repository name):
{
"name": "Python 3.11 Dev Container",
"image": "mcr.microsoft.com/vscode/devcontainers/python:3-11",
"forwardPorts": [8000],
"postCreateCommand": "pip install -r requirements.txt",
"customizations": {
"vscode": {
"extensions": ["ms-python.python"]
}
}
}
- Commit the changes to the repository (you need write permission on the repo):
git add .devcontainer/devcontainer.json
git commit -m "Add Python dev container configuration"
git push origin main
- Launch a Codespace from the GitHub UI (click “Code” → “Codespaces” → “New codespace”). The Codespace will pull the
mcr.microsoft.com/vscode/devcontainers/python:3-11image, run thepostCreateCommand, and make port 8000 available.
Validation and Practical Checks
After the Codespace starts, verify that the expected base image and tooling are present:
- Open a terminal inside the Codespace and run:
docker images | grep mcr.microsoft.com/vscode/devcontainers/python
You should see a line showing the image tag 3-11 and a size close to 800 MB.
- Check that Python is available and that your dependencies were installed:
python --version
pip list | grep -E "(your‑package|requirements)"
If the version matches 3.11 and your packages appear, the configuration succeeded.
Limitations and How to Mitigate Them
- Storage limit: Even though the Python image is ~800 MB, large repositories or heavy build artifacts can push the total over 2 GB. Mitigate by regularly cleaning
node_modules,__pycache__, or using.gitignoreto exclude unnecessary files. - Post‑creation time: The
postCreateCommandruns each time a Codespace is created. Keep it lightweight; if you notice long start‑up times, consider moving heavy installations into a custom Dockerfile that is built once and reused. - Image freshness: The Microsoft dev container images are updated periodically. To stay current, rebuild the Codespace occasionally or update the image tag in
devcontainer.jsonwhen a newer release is announced.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.