This directory contains Docker configurations for running Next.js applications in both development and production environments.
docker/
├── Dockerfile.development - Development container with hot reloading
├── Dockerfile.production - Production-optimized multi-stage build
├── docker-compose.development.yml - Development environment with mounted volumes
└── docker-compose.production.yml - Production environment configuration
The development Docker setup provides:
- Hot reloading for immediate feedback during development
- Volume mounting of the source code
- Isolated node_modules directory
- Development-specific environment variables
# Start the development environment
cd docker
docker-compose -f docker-compose.development.yml up
# Stop the development environment
docker-compose -f docker-compose.development.yml downThe production Docker setup features:
- Multi-stage build for optimized image size
- Running as a non-root user for enhanced security
- Health checks for container monitoring
- Resource limits for better predictability
- Only including necessary files
# Build and start the production environment
cd docker
docker-compose -f docker-compose.production.yml up -d
# Check container status
docker-compose -f docker-compose.production.yml ps
# View logs
docker-compose -f docker-compose.production.yml logs -f
# Stop the production environment
docker-compose -f docker-compose.production.yml down- The production Dockerfile runs as a non-root user (nextjs)
- Only necessary files are included in the final image
- NODE_ENV is set to production, disabling development features
- Health checks ensure the application is responding correctly
- Multi-stage builds reduce the final image size
- Only production dependencies are included
- Next.js telemetry is disabled
- Resource limits prevent container resource abuse
- Source code is mounted for immediate feedback
- Node modules are isolated to prevent host/container conflicts
- Environment variables can be easily configured for development
- Node Modules Conflicts - Ensure node_modules isn't mounted from host to container
- Build Context - The build context matters for relative paths in Dockerfiles
- Environment Variables - Make sure to pass all required environment variables
- Permissions - Watch for permission issues when mounting volumes
- Caching - Be aware of Docker's caching mechanisms during builds