Damp

DevContainers

VS Code DevContainer integration for seamless development

DAMP creates a complete VS Code DevContainer setup for every project, giving you a professional development environment that runs entirely inside Docker containers.

Full Development Environment

Edit code, debug, run commands - all inside a container with PHP, Node.js, Composer, and extensions pre-configured.

Project Structure

When you create a project, DAMP automatically generates this structure:

devcontainer.json
Dockerfile
php.ini
xdebug.ini
launch.json
index.php

Everything Pre-Configured

All files are generated automatically with smart defaults - just open in VS Code and start coding!

Key Features

Full Customization

Modify devcontainer.json, Dockerfile, and PHP configs per project

Network Isolation

Uses dedicated devnet Docker network for service communication

Fast Performance

Named Docker volumes instead of slow Windows bind mounts

XDebug Ready

Step-through debugging works out of the box

DevContainer Configuration

devcontainer.json

The heart of your development environment:

{
    "name": "myapp",
    "build": {
        "dockerfile": "./Dockerfile",
        "args": { "VARIANT": "8.3" }
    },
    "runArgs": [
        "--network=devnet",
        "--name", "myapp_devcontainer"
    ],
    "forwardPorts": [8080],
    "postStartCommand": "php artisan serve --host=0.0.0.0"
}

Key Settings:

  • --network=devnet - Connects to DAMP's shared network for Caddy/MySQL access
  • --name - Container naming pattern: {project-name}_devcontainer
  • forwardPorts - Exposes PHP dev server on port 8080

Network Requirement

The devnet network is essential - it allows your container to communicate with Caddy (web server) and MySQL services.

Docker Volumes for Speed

DAMP uses named Docker volumes instead of bind mounts:

{
    "workspaceMount": "source=myapp_volume,target=/workspace,type=volume",
    "workspaceFolder": "/workspace/myapp"
}

Why Volumes?

Bind Mounts (Slow)Named Volumes (Fast)
❌ Windows filesystem overhead✅ Native Docker filesystem
❌ Slow I/O operations✅ Lightning-fast reads/writes
❌ File watching issues✅ Reliable file change detection
❌ Permission problems✅ Consistent permissions

Performance Boost

Named volumes can be 10-20x faster than Windows bind mounts, especially for Composer and npm operations!

PHP Configuration

php.ini

Customize PHP settings per project:

; Custom PHP settings
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300

xdebug.ini

Pre-configured for debugging:

[xdebug]
zend_extension=xdebug
xdebug.mode=develop,debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal

Zero-Config Debugging

XDebug works immediately - just set breakpoints in VS Code and press F5!

Customization Workflow

Need to change something? Follow these steps:

Edit Configuration

Modify devcontainer.json, Dockerfile, or PHP config files directly in your project folder.

Rebuild Container

In VS Code, press Ctrl+Shift+P and run:

  • "Dev Containers: Rebuild Container"

Changes Applied

Your container rebuilds with the new configuration!

Common Customizations

Add PHP Extensions

Edit devcontainer.json:

{
    "features": {
        "ghcr.io/opencodeco/devcontainers/install-php-extensions:0": {
            "extensions": "bcmath pdo_mysql mysqli intl zip gd redis imagick"
        }
    }
}

Change PHP Version

Edit devcontainer.json:

{
    "build": {
        "args": {
            "VARIANT": "8.2"  // Change to 7.4, 8.0, 8.1, 8.2, 8.3
        }
    }
}

Add VS Code Extensions

Edit devcontainer.json:

{
    "customizations": {
        "vscode": {
            "extensions": [
                "bmewburn.vscode-intelephense-client",
                "xdebug.php-debug",
                "onecentlin.laravel-extension-pack"
            ]
        }
    }
}

Extensions Install Automatically

VS Code extensions listed in devcontainer.json install automatically when you open the container.

Laravel Projects

Laravel sites get special treatment:

{
    "postCreateCommand": "npm install && npm run build",
    "postStartCommand": "composer run devcontainer"
}

The devcontainer script runs:

  • ✅ PHP artisan serve (web server)
  • ✅ Queue worker
  • ✅ Pail (real-time logs)
  • ✅ Vite dev server (hot reload)

All services run concurrently with color-coded output!

Network Architecture

┌────────────────────────────────────┐
│       Docker Network: devnet       │
├────────────────────────────────────┤
│                                    │
│  ┌──────────────────────┐          │
│  │  Caddy Web Server    │          │
│  │  (damp-web)          │          │
│  └──────────┬───────────┘          │
│             │                      │
│             │ Reverse Proxy        │
│             ↓                      │
│  ┌──────────────────────┐          │
│  │ myapp_devcontainer   │          │
│  │ PHP 8.3 + Node.js    │          │
│  │ Port: 8080           │          │
│  └──────────┬───────────┘          │
│             │                      │
│             │ Database Connection  │
│             ↓                      │
│  ┌──────────────────────┐          │
│  │  MySQL Database      │          │
│  │  (damp-mysql)        │          │
│  └──────────────────────┘          │
│                                    │
└────────────────────────────────────┘

Container Naming:

  • Pattern: {project-name}_devcontainer
  • Example: myapp_devcontainer, blog_devcontainer

This naming allows Caddy to route traffic to the correct container.

VS Code Integration

Opening in DevContainer

  1. Open project folder in VS Code
  2. Click "Reopen in Container" notification
  3. VS Code rebuilds and attaches to container
  4. Start coding inside the container!

Debugging

Press F5 to start debugging with this configuration:

{
    "type": "php",
    "request": "launch",
    "name": "Listen for Xdebug",
    "port": 9003,
    "pathMappings": {
        "/workspace/myapp": "${workspaceFolder}"
    }
}

Debugging Tips

  • Breakpoints work immediately
  • Inspect variables in Debug panel
  • Step through code with F10/F11
  • View call stack and watch expressions

Best Practices

✅ Do

  • Commit devcontainer files to version control
  • Customize per project - each project can have different settings
  • Rebuild after changes - always rebuild container after editing config
  • Use named volumes - keep the default volume configuration for speed

❌ Don't

  • Don't modify running containers - changes won't persist
  • Don't use bind mounts - they're slow on Windows
  • Don't hardcode ports - use the defaults (8080)
  • Don't skip rebuild - config changes require container rebuild

Troubleshooting


Professional Development Environment

With DevContainers, you get a complete, isolated, and fast development setup that matches your production environment perfectly.