This is a base container for running Node.js applications, supporting multiple Node.js versions (18, 20, 22). The default is Node.js 20. The container is based on AlmaLinux 9 and uses Nginx as a reverse proxy with SSL. It is designed for both development and production use.
**You must have Docker or compatible containerization software running.**
---
## What's Included?
- **Multiple Node.js Versions:** 18, 20, 22 (set with `NODEVER` or `-a` flag)
- **PM2 Process Manager:** For production-grade Node.js application management
- **Nginx Reverse Proxy:** SSL-enabled reverse proxy with automatic HTTP to HTTPS redirect
- **Development Features:** Memcached for sessions, automatic backups, log rotation
- **Health Monitoring:** Built-in `/ping` endpoint for health checks
---
## Quick Start: Local Development with `local-dev.sh`
The easiest way to start a local development environment is with the provided `local-dev.sh` script. This script automates container setup, volume creation, log directories, and creates a sample Node.js application.
### Usage Example
```bash
./local-dev.sh -n local-dev
```
**Flags:**
-`-n` Name of the container (required)
-`-p` HTTP port (default: 80)
-`-s` HTTPS port (default: 443)
-`-r` Root path for files (default: current directory)
-`-a` Node.js version (default: 20; options: 18, 20, 22)
-`-v` Enable verbose mode
-`-h` Show help
The script will:
- Create a user directory and log folders
- Create a default Node.js Express application if none exists
- Start the container with the correct environment variables
- **Development**: 512MB-1GB (with all services enabled)
The container is optimized for memory efficiency with automatic memory management and process restarts. See `MEMORY-GUIDE.md` for detailed memory optimization information.
### Performance Features
- Automatic application restart at 256MB memory usage
- V8 heap limited to 200MB by default
- Nginx optimized for single-worker, low-memory operation
- Memcached limited to 32MB cache size
## Troubleshooting
- The first run may take a few minutes as Node.js and dependencies are installed
- If you need to change Node.js version, stop and remove the container, then recreate with the desired version
- For custom applications, ensure your `package.json` has a valid start script
- Check `/home/$user/logs/nodejs/error.log` for application errors
- The health check endpoint `/ping` should return a 200 status when the application is running properly
- **Memory issues**: Run `/scripts/memory-info.sh` inside container to check memory usage
- **Process monitoring**: Use `pm2 monit` to watch application performance