Bare bones dockerized starter for Node.js applications using pnpm.
- Node.js 18 Alpine-based Docker container
- pnpm package manager for faster, more efficient dependency management
- Environment variable configuration
- Docker Compose setup for easy development
- Non-root user for security
- Hot reload with nodemon in development
- Docker
- Docker Compose
- pnpm (for local development)
-
Clone and navigate to the project:
cd node-docker-template -
Copy the environment example file:
cp env.example .env
-
Configure your environment variables in
.env:# Application Configuration APP_NAME=My App PORT=3000 # Node.js Configuration NODE_ENV=development
-
Build and run with Docker Compose:
docker-compose up --build
-
Install pnpm (if not already installed):
npm install -g pnpm
-
Install dependencies:
pnpm install
-
Run in development mode:
pnpm run dev
-
Run in production mode:
pnpm start
-
Build the image:
docker build -t node-docker-template . -
Run the container:
docker run --env-file .env node-docker-template
| Variable | Description | Required | Default |
|---|---|---|---|
APP_NAME |
Application name | No | World |
PORT |
Application port | No | 3000 |
NODE_ENV |
Node.js environment | No | development |
node-docker-template/
├── src/
│ └── index.js # Main application file
├── package.json # Node.js dependencies and scripts
├── pnpm-lock.yaml # pnpm lockfile (auto-generated)
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── env.example # Environment variables example
├── .gitignore # Git ignore rules
└── README.md # This file
- Faster installations - Up to 2x faster than npm
- Disk space efficient - Uses hard links and symlinks to save space
- Strict dependency resolution - Prevents phantom dependencies
- Better monorepo support - Built-in workspace features
This template provides a minimal foundation that can be easily extended:
- Add your application logic to
src/index.js - Add dependencies with
pnpm add <package> - Add dev dependencies with
pnpm add -D <package> - Modify the Dockerfile for specific requirements
- Update environment variables as needed
# Install dependencies
pnpm install
# Add a dependency
pnpm add express
# Add a dev dependency
pnpm add -D nodemon
# Run scripts
pnpm start
pnpm dev
# Build and run with Docker
docker-compose up --build
# Build Docker image only
docker build -t node-docker-template .- Uses non-root user in Docker container
- Environment variables for configuration
- Alpine Linux base image for smaller attack surface
- Production-ready configuration
MIT