Docker Development Guide
This guide explains how to use Docker containers for development, testing, and building in the Screeps GPT repository.
Overview
The repository provides Docker containerization for:
- Testing: Isolated test environments with specific Node.js versions
- Building: Consistent build environments
- Development: Complete development setup with hot-reload support
- CI/CD Integration: Reproducible environments matching CI pipelines
Prerequisites
- Docker 20.10 or later
- Docker Compose v2.0 or later (typically included with Docker Desktop)
Available Containers
Test Container (Dockerfile.test)
Purpose: Run unit, end-to-end, and regression tests
Environment:
- Node.js 20 (required for Vitest 4.x)
- Python 2.7 (for native dependency compilation)
- Full test dependencies
Usage:
1 | # Run unit tests |
Build Container (Dockerfile.build)
Purpose: Build the Screeps AI bundle
Environment:
- Node.js 20
- Build dependencies (esbuild, TypeScript, tsx)
- No optional dependencies (lightweight)
Usage:
1 | # Build the AI |
Mockup Container (Dockerfile.mockup)
Purpose: Run screeps-server-mockup tests (requires Node.js 16)
Environment:
- Node.js 16.20.2 (last version supporting Python 2 native modules)
- Python 2.7
- screeps-server-mockup and isolated-vm dependencies
Usage:
1 | # Run mockup tests |
Note: This container is separate because screeps-server-mockup requires Node.js 16 with Python 2 for the isolated-vm native module.
Development Workflow
Initial Setup
Build containers:
1
npm run docker:build
Run tests to verify setup:
1
npm run docker:test:unit
Iterative Development
The containers use volume mounting to reflect local changes immediately:
1 | # Start development server with hot-reload |
Quality Checks
Run linting and formatting checks:
1 | # Run ESLint |
Interactive Debugging
Access a shell inside the test container for debugging:
1 | npm run docker:shell |
Docker Compose Services
The docker-compose.yml file defines multiple services:
dev Service
- Purpose: Development with hot-reload
- Command:
npm run build:watch - Volumes: Full workspace with node_modules excluded
test Service
- Purpose: Testing environment
- Command: Configurable (unit, e2e, regression tests)
- Volumes: Workspace with node_modules excluded
build Service
- Purpose: Build the AI bundle
- Command:
npm run build - Volumes: Workspace with node_modules excluded
lint Service
- Purpose: Run linting checks
- Command:
npm run lint
format Service
- Purpose: Check code formatting
- Command:
npm run format:check
mockup Service
- Purpose: Run mockup tests (Node.js 16)
- Command:
npm run test:mockup
Volume Mounting Strategy
The containers use the following volume mounting strategy:
1 | volumes: |
This ensures:
- Code changes are immediately available in containers
- Container-specific node_modules are isolated
- No conflicts between host and container dependencies
Security Considerations
SSL Certificate Handling
The Dockerfiles disable strict SSL during npm install to handle self-signed certificates in containerized environments:
1 | RUN npm config set strict-ssl false && \ |
This is acceptable for development containers but should not be used in production deployments.
Python 2 Dependencies
Python 2 is required for compiling native Node.js modules (isolated-vm in screeps-server-mockup). While Python 2 is EOL, it’s necessary for maintaining compatibility with the Screeps testing infrastructure.
CI/CD Integration
The Docker containers can be integrated into GitHub Actions workflows for consistency:
1 | # Example workflow step |
This ensures the CI environment matches local development environments.
Troubleshooting
Container Build Failures
Problem: npm install fails with SSL errors
Solution: The Dockerfiles already include SSL workarounds. If issues persist:
1 | # Rebuild without cache |
Problem: isolated-vm fails to build
Solution: This is expected in the build container, which excludes optional dependencies. Use the mockup container for isolated-vm tests:
1 | npm run docker:test:mockup |
Volume Mounting Issues
Problem: Changes not reflected in container
Solution: Ensure Docker has access to the workspace directory:
- macOS: Check Docker Desktop → Preferences → Resources → File Sharing
- Windows: Check Docker Desktop → Settings → Resources → File Sharing
- Linux: Ensure user has Docker permissions
Problem: node_modules conflicts
Solution: Remove local node_modules and rebuild:
1 | rm -rf node_modules |
Performance Issues
Problem: Slow builds or tests
Solution:
- Increase Docker resources: Docker Desktop → Preferences → Resources
- Use BuildKit: Already enabled by default in Docker Compose v2
- Prune unused images:
docker system prune -a
Permission Issues (Linux)
Problem: Permission denied when accessing files created by containers
Solution: The containers run as root by default. To match host user permissions:
1 | # Run container with host user ID |
Problem: Cannot delete dist/ directory created by Docker build container
Solution: Files created by Docker containers are owned by root. Clean with:
1 | sudo rm -rf dist |
Alternatively, run the build container with host user permissions:
1 | docker compose run --rm --user $(id -u):$(id -g) build |
Performance Optimization
Build Caching
Docker layer caching is optimized by copying package files before source code:
1 | COPY package.json package-lock.json ./ |
This ensures dependency installation is cached unless package files change.
Multi-Stage Builds
The build container is optimized by excluding optional dependencies:
1 | npm install --no-optional |
This reduces image size and build time when optional dependencies (like screeps-server-mockup) aren’t needed.
Version Requirements
Node.js Versions
- Test/Build Containers: Node.js 20 (required for Vitest 4.x and modern tooling)
- Mockup Container: Node.js 16.20.2 (required for isolated-vm with Python 2)
Python Version
- All Containers: Python 2.7.18 (required for node-gyp with legacy native modules)
Migration from Local Development
To migrate from local development to Docker:
- Commit changes: Ensure working tree is clean
- Build containers:
npm run docker:build - Test compatibility:
npm run docker:test:unit - Update workflows: Replace local commands with
docker:*equivalents - Document changes: Update team documentation
Backward Compatibility
All existing npm commands continue to work without Docker:
1 | # Traditional commands (still work) |
This ensures gradual adoption without disrupting existing workflows.
Related Documentation
- Deployment Troubleshooting - Deployment issues and solutions
- Workflow Troubleshooting - GitHub Actions debugging
- Repository README - Main repository documentation
Future Enhancements
Potential improvements for Docker containerization:
- Multi-architecture builds: Support for ARM64 (Apple Silicon)
- Production deployment container: Optimized container for Screeps deployment
- Remote development: VSCode Dev Containers integration
- CI/CD optimization: Parallel container builds in GitHub Actions
- Kubernetes support: Deployment configurations for K8s environments
Support
For issues with Docker containerization:
- Check Troubleshooting section
- Review GitHub Issues
- Consult Docker documentation
- Ask in repository discussions