Overview
The API is containerized using Docker with a production-ready configuration. A pre-built image is available on Docker Hub for quick deployment.Docker Hub Image
luis159/stripe-back:latestBase Image
node:20-alpineDockerfile Configuration
The API uses an optimized Dockerfile for production deployments:- Uses Alpine Linux for minimal image size
- Installs only production dependencies with
npm ci --omit=dev - Sets production environment by default
- Exposes port 3000
- Runs with
npm startcommand
Method 1: Docker Compose (Local Development)
The recommended approach for local development is using Docker Compose.STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxx
PORT=3000
NODE_ENV=production
services:
api:
build: .
container_name: stripe-back-api
env_file:
- .env
ports:
- "3000:3000"
restart: unless-stopped
stripe-back-api.envMethod 2: Pre-built Docker Hub Image
For quick deployment without building from source, use the pre-built image.docker run -d \
--name stripe-back-api \
-p 3000:3000 \
-e STRIPE_SECRET_KEY=sk_test_xxxxxxxxxxxxx \
-e STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxxxxxxx \
-e NODE_ENV=production \
--restart unless-stopped \
luis159/stripe-back:latest
-d: Run in detached mode--name: Container name-p 3000:3000: Port mapping (host:container)-e: Environment variables--restart: Restart policydocker run -d \
--name stripe-back-api \
-p 3000:3000 \
--env-file .env \
--restart unless-stopped \
luis159/stripe-back-api:latest
CONTAINER ID IMAGE STATUS PORTS
abc123def456 luis159/stripe-back:latest Up 10 seconds 0.0.0.0:3000->3000/tcp
Method 3: Build from Source
If you need to customize the image or work with local changes:Environment Variables
Required environment variables for deployment:| Variable | Description | Required | Example |
|---|---|---|---|
STRIPE_SECRET_KEY | Stripe API secret key | Yes | sk_test_... |
STRIPE_WEBHOOK_SECRET | Webhook signing secret | Yes | whsec_... |
PORT | Application port | No | 3000 (default) |
NODE_ENV | Node environment | No | production (default) |
The Dockerfile sets
NODE_ENV=production and PORT=3000 by default. You can override these with environment variables.Health Check
Verify the API is running:Production Deployment Tips
Use Specific Tags
Instead of
latest, use specific version tags in production:Resource Limits
Set memory and CPU limits for production:
Volume Mounting
If your app needs persistent storage:
Network Configuration
For multi-container setups, use Docker networks:
Docker Compose for Production
For production deployments with additional services:docker-compose.prod.yml
Troubleshooting
Container exits immediately
Container exits immediately
Check the logs for errors:Common issues:
- Missing required environment variables
- Port 3000 already in use
- Invalid Stripe credentials
Cannot connect to the API
Cannot connect to the API
- Verify the container is running:
docker ps - Check port mapping:
docker port stripe-back-api - Test from inside the container:
Environment variables not loading
Environment variables not loading
Ensure your
.env file:- Is in the same directory as your docker-compose.yml
- Has no quotes around values (unless needed)
- Uses the correct variable names
- Has Unix line endings (LF, not CRLF)
Build fails with dependency errors
Build fails with dependency errors
If building from source fails:
Container Management
Common Commands
Next Steps
- Configure webhook testing in your Docker environment
- Review error handling patterns
- Follow the complete payment workflow