The Storage Death Spiral (And How to Stop It)

Docker

Your codespace just crashed with ENOSPC: no space left on device during npm install. Docker layers are eating your disk space faster than you can delete them. Here's what actually works.

The Quick Fix (Nuclear Option)

When you're getting the disk space error, this will save your ass right now:

docker system prune -a --force
docker builder prune --all --force

This nukes everything Docker-related and frees up 5-10GB instantly. You'll have to rebuild your containers, but at least you can work.

Why This Keeps Happening

GitHub gives you 32GB of disk space per codespace, which sounds like plenty until you realize:

The Real Solution: Devcontainer Optimization

Edit your .devcontainer/devcontainer.json to include cleanup commands:

{
  "initializeCommand": "docker system prune --force",
  "postCreateCommand": "npm ci && npm run build",
  "shutdownAction": "stopContainer"
}

The initializeCommand runs before your container starts, cleaning up leftover Docker garbage. This prevented me from hitting the disk limit for 3 months straight.

Storage Monitoring That Actually Works

Add this to your shell startup file (.bashrc or .zshrc):

## Check disk space on every terminal start
df -h | grep -E "Size|/$" && echo "Docker space:" && docker system df

Now you'll see exactly how much space you have left every time you open a terminal. When Docker is using more than 10GB, it's time to run docker system prune with proper cleanup strategies.

Docker Layer Hell: The Specific Fix

If you're building Docker images inside Codespaces (yes, Docker-in-Docker), your .devcontainer/Dockerfile is probably wasteful following anti-patterns:

BAD (creates 5 layers):

RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y curl
RUN apt-get install -y vim
RUN apt-get clean

GOOD (creates 1 layer):

RUN apt-get update \
    && apt-get install -y git curl vim \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

This single change reduced my container size from 2.1GB to 800MB following Docker layer optimization. Multiply that by 10 rebuilds and you just saved 13GB per storage efficiency guidelines.

The npm/yarn Storage Bomb

Node.js projects are the worst offenders. Here's the pattern that kills storage:

  1. npm install downloads 300MB of dependencies
  2. Rebuild container → npm install again → another 300MB
  3. Switch branches → npm install → another 300MB
  4. Repeat until dead

Solution: Use npm/yarn cache properly in your devcontainer:

{
  "mounts": [
    "source=node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
  ],
  "postCreateCommand": "npm ci"
}

This mounts node_modules as a Docker volume, so it persists between container rebuilds. One npm install, reused forever.

The Machine Type Trap

Upgrading to 4-core or 8-core machines gives you more disk space:

  • 2-core: 32GB storage
  • 4-core: 64GB storage
  • 8-core: 128GB storage

But here's the gotcha: bigger machines don't fix wasteful Docker usage. I've seen developers burn through 128GB in a week by not cleaning up layers.

Fix your Docker hygiene first, then upgrade machine size if you legitimately need more space.

When Storage Monitoring Saves Your Ass

Set up automatic cleanup in your devcontainer configuration:

{
  "initializeCommand": [
    "bash -c 'USED=$(df / | tail -1 | awk \"{print \$5}\" | sed \"s/%//\"); if [ $USED -gt 80 ]; then docker system prune -f; fi'"
  ]
}

This automatically runs docker system prune if disk usage goes above 80%. Saved me from the "no space left" error at least a dozen times.

Production Troubleshooting FAQ

Q

My codespace won't start and says "Failed to create codespace"

A

First thing to check: repository permissions. If your repo is private and you're on a free GitHub plan, you might be hitting the private repository limit. Switch to a public repo or upgrade to Pro.If that's not it, check your .devcontainer/devcontainer.json syntax. One missing comma breaks everything:bash# Validate your JSONcat .devcontainer/devcontainer.json | jq .If that errors out, fix your JSON. If it's valid, try deleting and recreating the codespace—sometimes GitHub's VM allocation just fails.

Q

My codespace keeps shutting down while I'm using it

A

You probably have idle timeout settings that are too aggressive. But here's the sneaky issue: Codespaces considers you "idle" if VS Code isn't in focus.Switch to another window to check documentation? Codespace might shut down. Check your email during a long build? Also shut down.The fix: keep a terminal running while true; do echo "alive"; sleep 300; done during long operations. Or increase your timeout to 120 minutes.

Q

Docker commands fail with "permission denied"

A

Your user isn't in the docker group. Add this to your .devcontainer/devcontainer.json:json{"postCreateCommand": "sudo usermod -aG docker $USER && newgrp docker","remoteUser": "vscode"}If you're getting Cannot connect to the Docker daemon errors, the Docker service isn't running inside your container. This happens when you use a minimal base image. Switch to mcr.microsoft.com/vscode/devcontainers/base:ubuntu which has Docker pre-installed.

Q

Port forwarding isn't working with my React/Next.js app

A

React dev server binds to localhost by default, which doesn't work with Codespaces port forwarding. You need to bind to 0.0.0.0:bash# For Create React AppHOST=0.0.0.0 npm start# For Next.jsnext dev -H 0.0.0.0# For Vitevite --host 0.0.0.0Or set this in your package.json:json{"scripts": {"dev": "next dev -H 0.0.0.0 -p 3000"}}If you're still getting connection refused, check if your process is actually listening on all interfaces: netstat -tlnp | grep :3000

Q

My environment variables aren't loading

A

GitHub Codespaces doesn't automatically load .env files.

You have three options:

  1. Add secrets in GitHub settings:

Go to Settings → Codespaces → Repository secrets. These get loaded automatically.2. Source .env manually: Add this to your shell startup:bashexport $(cat .env | xargs)3. Use dotenv in your devcontainer:

Add to .devcontainer/devcontainer.json:json{"postCreateCommand": "cp .env.example .env"}

Q

My build process is insanely slow

A

Codespaces VMs use shared CPU, so performance varies by time of day. But the real killer is usually inefficient Docker builds.Run docker system df to see what's eating your resources. If "Build Cache" is over 5GB, run docker builder prune immediately.For Node.js projects, use .dockerignore to avoid copying node_modules:node_modules.git.env*.logAnd use multi-stage builds to avoid including dev dependencies in your final image.

Q

I can't install global npm packages

A

You're probably running as the vscode user without sudo access. Two fixes:Fix 1: Configure npm to use a user directory:bashmkdir ~/.npm-globalnpm config set prefix '~/.npm-global'export PATH=~/.npm-global/bin:$PATHFix 2: Give vscode user sudo access in your devcontainer:json{"features": {"ghcr.io/devcontainers/features/common-utils:1": {"username": "vscode","userUid": 1000,"userGid": 1000}},"remoteUser": "vscode"}

Q

My database connections keep failing

A

If you're trying to connect to localhost:5432 inside your codespace, that's not going to work.

Database containers inside Codespaces need to be accessible via service name:```yaml# docker-compose.ymlversion: '3'services: db: image: postgres:13 container_name: postgres_db # Don't use localhost

  • use the service name "db"```Then connect to db:5432, not localhost:5432. For external databases, check if your connection string includes SSL requirements. Many cloud databases require sslmode=require.
Q

My extensions won't sync between codespaces

A

VS Code settings sync doesn't work automatically in Codespaces.

Enable it manually: 1.

Open VS Code settings (Ctrl+,)2. Search for "Settings Sync"3. Turn on "Settings Sync: Enabled"4.

Sign in with your GitHub or Microsoft accountOr define extensions in your devcontainer:json{"extensions": ["ms-python.python","ms-vscode.vscode-typescript-next","esbenp.prettier-vscode"]}

Q

My SSH keys aren't working inside the codespace

A

GitHub automatically forwards your SSH keys to Codespaces, but only if you've uploaded them to your GitHub profile first. Check Settings → SSH and GPG keys.If they're uploaded but still not working, restart your codespace. SSH agent forwarding sometimes breaks on codespace resume.

Performance Hell: When Your Codespace Crawls

VS Code

Your codespace takes 5 minutes to start. VS Code is laggy as hell. npm install runs slower than on your local machine from 2019. Here's what's actually broken and how to fix it.

The Prebuild Trap

Everyone says "use prebuilds" but nobody explains the gotcha: prebuilds are region-specific. If GitHub spins up your codespace in a different Azure region than where your prebuild ran, you get no benefit. You're back to cold-starting every damn time per GitHub's regional limitations.

The fix is forcing your codespace region in your organization settings, but you need GitHub Team or Enterprise for this. Individual accounts get whatever region GitHub feels like per account limitations.

{
  "prebuild": {
    "commands": [
      "npm ci",
      "npm run build"
    ],
    "trigger": {
      "pullRequest": true,
      "push": true
    }
  }
}

But here's the thing: if your npm ci takes longer than 45 minutes, the prebuild times out and fails silently. Check your prebuild logs because they probably failed weeks ago per GitHub Actions timeout behavior.

RAM Starvation on 2-Core Machines

The default 2-core machine gives you 4GB RAM. That sounds fine until your React app needs 2GB, your database needs 1GB, and VS Code wants another 1GB. Now you're swapping to disk constantly per memory constraints.

Don't upgrade your machine type immediately. First, check what's actually using memory with system monitoring:

## See which processes are memory hogs
ps aux --sort=-%mem | head -10

## Check if you're swapping
free -h

Common memory killers in development:

  • Webpack dev server: Can use 1-2GB with source maps
  • Jest watch mode: Keeps test files in memory indefinitely
  • Multiple Node processes: Each npm start in different projects
  • Docker builds: Can temporarily spike to 3-4GB

The quick fix for Node.js memory issues:

export NODE_OPTIONS="--max-old-space-size=2048"

This limits Node to 2GB instead of trying to use all available RAM.

The Network Performance Cliff

Your internet speed doesn't matter once you're inside the codespace, but your latency to GitHub's servers does. If you're in Australia connecting to a US East codespace, every keystroke has 200ms lag.

There's no perfect solution, but you can minimize the pain:

  1. Use GitHub CLI for commits: gh commands are faster than VS Code's Git integration
  2. Batch file operations: Copy-paste multiple files instead of one-by-one saves
  3. Use local VS Code: Desktop VS Code connecting to codespaces has less network overhead than browser VS Code

Docker Build Performance Disasters

Building Docker images inside Codespaces is 3-5x slower than local because of the virtualization overhead. But the real killer is not using BuildKit.

Add this to your .devcontainer/devcontainer.json:

{
  "initializeCommand": "export DOCKER_BUILDKIT=1",
  "build": {
    "dockerfile": "Dockerfile",
    "options": ["--progress=plain"]
  }
}

BuildKit enables parallel layer builds and better caching. I've seen 15-minute builds drop to 3 minutes with this alone.

The Extension Performance Killer

VS Code extensions run on your codespace's CPU, not your local machine. Heavy extensions can make everything sluggish:

Performance killers:

  • Auto-formatting on every keystroke
  • Real-time linting for large files
  • AI coding assistants (GitHub Copilot uses 10-20% CPU constantly)
  • Language servers for large codebases

Quick fix: Disable extensions you don't need in your devcontainer:

{
  "extensions": [
    "ms-python.python"
  ],
  "settings": {
    "editor.formatOnSave": false,
    "editor.formatOnType": false
  }
}

Database Performance: The Connection Pool Problem

If your app is connecting to a database inside the codespace, you're probably not using connection pooling. Every new HTTP request creates a new DB connection, which is slow and eventually hits connection limits.

For Node.js apps using PostgreSQL:

// BAD: New connection per request
const client = new Client({
  host: 'localhost',
  user: 'postgres',
  password: 'password'
});

// GOOD: Connection pool
const { Pool } = require('pg');
const pool = new Pool({
  host: 'localhost',
  user: 'postgres', 
  password: 'password',
  max: 10, // Maximum connections
  idleTimeoutMillis: 30000
});

This single change took my API response times from 800ms to 50ms.

The File Watcher Explosion

VS Code watches all files in your workspace for changes. In a large monorepo, this can be thousands of files. Each file watch uses CPU and memory.

Solution: Configure VS Code to ignore directories you don't care about:

{
  "files.watcherExclude": {
    "**/node_modules/**": true,
    "**/dist/**": true,
    "**/build/**": true,
    "**/.git/**": true
  }
}

This reduced my CPU usage from 60% to 15% in a 50,000-file repository.

When Upgrading Machine Type Actually Helps

Upgrade from 2-core to 4-core when:

  • Your npm install consistently takes over 5 minutes
  • Docker builds take over 10 minutes
  • You're running 3+ services simultaneously (app, database, Redis, etc.)
  • VS Code becomes unresponsive during file saves

Don't upgrade for:

  • Network lag issues (won't help)
  • Storage problems (fix Docker hygiene first)
  • Single-threaded processes (more cores won't speed up pip install)

The Cost vs Performance Reality

4-core machines cost 2x as much but aren't always 2x faster. Profile your actual bottlenecks first:

## Check CPU usage during your slowest operations
top -p $(pgrep -f "npm|node|python|docker")

## Check disk I/O (often the real bottleneck)
iostat -x 1

If CPU usage stays under 70% during slow operations, more cores won't help. You probably have a disk I/O or network bottleneck instead.

Machine Type Troubleshooting Guide

Problem

2-Core Solution

4-Core Solution

8-Core Solution

When to Upgrade

npm install takes >5 min

Use npm ci instead of install

Parallel dependency resolution works better

Max benefit achieved

2-core → 4-core

Docker builds timeout

Use multi-stage builds, .dockerignore

BuildKit parallel layers help

Significant improvement

2-core → 4-core

VS Code lag during typing

Disable heavy extensions

More responsive with multiple services

Overkill for basic editing

Stay on 2-core

Jest tests run slowly

Use --maxWorkers=2

Can use --maxWorkers=4

--maxWorkers=8 shows gains

2-core → 4-core

Database queries timeout

Add connection pooling

More concurrent connections possible

Handles heavy query loads

Depends on usage

Webpack dev build slow

Disable source maps in dev

Faster compilation with more cores

Hot reload becomes instant

4-core for React/Vue

Out of memory errors

4GB RAM limit hit

8GB handles larger apps

16GB for ML/data work

When swap usage >50%

Multiple services (app+db+redis)

One service fails frequently

Can handle 3-4 services

All services run smoothly

2-core → 4-core

Python data processing

Use smaller datasets

pandas operations 2x faster

Multi-threading libraries shine

4-core → 8-core

File search in large repos

Takes 10+ seconds

3-5 seconds typical

Under 2 seconds

When search is daily task

Troubleshooting Resources That Actually Help

Related Tools & Recommendations

troubleshoot
Similar content

Fix Docker Daemon Not Running on Linux: Troubleshooting Guide

Your containers are useless without a running daemon. Here's how to fix the most common startup failures.

Docker Engine
/troubleshoot/docker-daemon-not-running-linux/daemon-startup-failures
100%
troubleshoot
Similar content

Docker 'No Space Left on Device' Error: Fast Fixes & Solutions

Stop Wasting Hours on Disk Space Hell

Docker
/troubleshoot/docker-no-space-left-on-device-fix/no-space-left-on-device-solutions
80%
troubleshoot
Recommended

Docker Won't Start on Windows 11? Here's How to Fix That Garbage

Stop the whale logo from spinning forever and actually get Docker working

Docker Desktop
/troubleshoot/docker-daemon-not-running-windows-11/daemon-startup-issues
72%
howto
Recommended

Stop Docker from Killing Your Containers at Random (Exit Code 137 Is Not Your Friend)

Three weeks into a project and Docker Desktop suddenly decides your container needs 16GB of RAM to run a basic Node.js app

Docker Desktop
/howto/setup-docker-development-environment/complete-development-setup
72%
news
Recommended

Docker Desktop's Stupidly Simple Container Escape Just Owned Everyone

integrates with Technology News Aggregation

Technology News Aggregation
/news/2025-08-26/docker-cve-security
72%
troubleshoot
Similar content

Fix Docker Permission Denied on Mac M1: Troubleshooting Guide

Because your shiny new Apple Silicon Mac hates containers

Docker Desktop
/troubleshoot/docker-permission-denied-mac-m1/permission-denied-troubleshooting
67%
tool
Similar content

LM Studio Performance: Fix Crashes & Speed Up Local AI

Stop fighting memory crashes and thermal throttling. Here's how to make LM Studio actually work on real hardware.

LM Studio
/tool/lm-studio/performance-optimization
65%
tool
Similar content

Node.js Production Troubleshooting: Debug Crashes & Memory Leaks

When your Node.js app crashes in production and nobody knows why. The complete survival guide for debugging real-world disasters.

Node.js
/tool/node.js/production-troubleshooting
61%
tool
Similar content

Webpack: The Build Tool You'll Love to Hate & Still Use in 2025

Explore Webpack, the JavaScript build tool. Understand its powerful features, module system, and why it remains a core part of modern web development workflows.

Webpack
/tool/webpack/overview
59%
tool
Similar content

Debugging AI Coding Assistant Failures: Copilot, Cursor & More

Your AI assistant just crashed VS Code again? Welcome to the club - here's how to actually fix it

GitHub Copilot
/tool/ai-coding-assistants/debugging-production-failures
59%
tool
Similar content

Git Disaster Recovery & CVE-2025-48384 Security Alert Guide

Learn Git disaster recovery strategies and get immediate action steps for the critical CVE-2025-48384 security alert affecting Linux and macOS users.

Git
/tool/git/disaster-recovery-troubleshooting
56%
integration
Similar content

Jenkins Docker Kubernetes CI/CD: Deploy Without Breaking Production

The Real Guide to CI/CD That Actually Works

Jenkins
/integration/jenkins-docker-kubernetes/enterprise-ci-cd-pipeline
52%
tool
Similar content

Certbot: Get Free SSL Certificates & Simplify Installation

Learn how Certbot simplifies obtaining and installing free SSL/TLS certificates. This guide covers installation, common issues like renewal failures, and config

Certbot
/tool/certbot/overview
50%
tool
Similar content

pandas Overview: What It Is, Use Cases, & Common Problems

Data manipulation that doesn't make you want to quit programming

pandas
/tool/pandas/overview
50%
tool
Similar content

React Production Debugging: Fix App Crashes & White Screens

Five ways React apps crash in production that'll make you question your life choices.

React
/tool/react/debugging-production-issues
50%
tool
Similar content

PostgreSQL: Why It Excels & Production Troubleshooting Guide

Explore PostgreSQL's advantages over other databases, dive into real-world production horror stories, solutions for common issues, and expert debugging tips.

PostgreSQL
/tool/postgresql/overview
50%
troubleshoot
Similar content

Fix Docker Networking Issues: Troubleshooting Guide & Solutions

When containers can't reach shit and the error messages tell you nothing useful

Docker Engine
/troubleshoot/docker-cve-2024-critical-fixes/network-connectivity-troubleshooting
50%
tool
Similar content

Fix TaxAct Errors: Login, WebView2, E-file & State Rejection Guide

The 3am tax deadline debugging guide for login crashes, WebView2 errors, and all the shit that goes wrong when you need it to work

TaxAct
/tool/taxact/troubleshooting-guide
50%
tool
Similar content

TaxBit Enterprise Production Troubleshooting: Debug & Fix Issues

Real errors, working fixes, and why your monitoring needs to catch these before 3AM calls

TaxBit Enterprise
/tool/taxbit-enterprise/production-troubleshooting
50%
tool
Recommended

VS Code Team Collaboration & Workspace Hell

How to wrangle multi-project chaos, remote development disasters, and team configuration nightmares without losing your sanity

Visual Studio Code
/tool/visual-studio-code/workspace-team-collaboration
47%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization