docker.recipes

KeystoneJS for E-commerce

intermediate

Node.js CMS for headless commerce.

Overview

KeystoneJS is a modern, TypeScript-first headless CMS and application framework built on Node.js that provides a GraphQL API and admin interface for content management. Originally developed by Thinkmill, KeystoneJS has evolved into a powerful platform for building complex data-driven applications, offering a code-first approach to schema definition with automatic admin UI generation and type-safe database operations through Prisma ORM. This stack combines KeystoneJS with PostgreSQL to create a robust foundation for headless e-commerce applications. KeystoneJS handles content management, user authentication, and GraphQL API generation, while PostgreSQL provides ACID-compliant data storage with advanced features like JSON support for flexible product catalogs and full-text search capabilities for product discovery. The integration leverages PostgreSQL's relational strengths for complex e-commerce queries involving orders, inventory, and customer relationships. This combination is ideal for developers building modern e-commerce platforms who need the flexibility of a headless architecture with the robustness of enterprise-grade data management. E-commerce businesses requiring custom admin interfaces, complex product catalogs, multi-channel content delivery, and sophisticated business logic will benefit from KeystoneJS's extensible hook system and PostgreSQL's advanced querying capabilities.

Key Features

  • Auto-generated GraphQL API with built-in playground for testing product queries and mutations
  • TypeScript-first schema definition with automatic type generation for e-commerce entities
  • Built-in admin interface with customizable forms for managing products, orders, and customers
  • Prisma ORM integration providing type-safe database operations and migrations
  • Hook system for implementing custom e-commerce logic like inventory updates and order processing
  • Session-based authentication with configurable access control for different user roles
  • PostgreSQL JSONB support for flexible product attributes and metadata storage
  • Full-text search capabilities through PostgreSQL for product catalog searches

Common Use Cases

  • 1Headless e-commerce platforms requiring custom frontend applications across web and mobile
  • 2Multi-tenant marketplaces with different seller dashboards and product catalogs
  • 3B2B commerce platforms with complex pricing rules and customer-specific product visibility
  • 4Content-rich e-commerce sites combining product catalogs with editorial content management
  • 5Inventory management systems requiring real-time stock tracking and automated reordering
  • 6Subscription-based commerce platforms with recurring billing and customer portal functionality
  • 7International e-commerce sites requiring multi-currency support and localized product data

Prerequisites

  • Docker Engine 20.10+ and Docker Compose V2 for container orchestration
  • Minimum 1GB RAM for PostgreSQL optimal performance with e-commerce workloads
  • Port 3000 available for KeystoneJS admin interface and GraphQL API access
  • Basic understanding of GraphQL queries and mutations for API interaction
  • Node.js and TypeScript knowledge for custom schema development and hooks
  • Familiarity with Prisma ORM concepts for database schema management

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 keystone:
3 image: keystonejs/keystone:latest
4 container_name: keystone
5 restart: unless-stopped
6 environment:
7 DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
8 SESSION_SECRET: ${SESSION_SECRET}
9 ports:
10 - "3000:3000"
11 depends_on:
12 - postgres
13 networks:
14 - keystone
15
16 postgres:
17 image: postgres:16-alpine
18 container_name: keystone-postgres
19 environment:
20 POSTGRES_DB: ${DB_NAME}
21 POSTGRES_USER: ${DB_USER}
22 POSTGRES_PASSWORD: ${DB_PASSWORD}
23 volumes:
24 - postgres_data:/var/lib/postgresql/data
25 networks:
26 - keystone
27
28volumes:
29 postgres_data:
30
31networks:
32 keystone:
33 driver: bridge

.env Template

.env
1DB_NAME=keystone
2DB_USER=keystone
3DB_PASSWORD=changeme
4SESSION_SECRET=your-session-secret

Usage Notes

  1. 1Docs: https://keystonejs.com/docs
  2. 2Admin UI at http://localhost:3000 - create admin on first visit
  3. 3GraphQL API built-in at /api/graphql with Playground
  4. 4Define schemas in schema.ts: lists for products, orders, users
  5. 5TypeScript-first with Prisma ORM for database
  6. 6Hooks and access control for custom business logic

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

keystone
keystone:
  image: keystonejs/keystone:latest
  container_name: keystone
  restart: unless-stopped
  environment:
    DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
    SESSION_SECRET: ${SESSION_SECRET}
  ports:
    - "3000:3000"
  depends_on:
    - postgres
  networks:
    - keystone
postgres
postgres:
  image: postgres:16-alpine
  container_name: keystone-postgres
  environment:
    POSTGRES_DB: ${DB_NAME}
    POSTGRES_USER: ${DB_USER}
    POSTGRES_PASSWORD: ${DB_PASSWORD}
  volumes:
    - postgres_data:/var/lib/postgresql/data
  networks:
    - keystone

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 keystone:
5 image: keystonejs/keystone:latest
6 container_name: keystone
7 restart: unless-stopped
8 environment:
9 DATABASE_URL: postgres://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
10 SESSION_SECRET: ${SESSION_SECRET}
11 ports:
12 - "3000:3000"
13 depends_on:
14 - postgres
15 networks:
16 - keystone
17
18 postgres:
19 image: postgres:16-alpine
20 container_name: keystone-postgres
21 environment:
22 POSTGRES_DB: ${DB_NAME}
23 POSTGRES_USER: ${DB_USER}
24 POSTGRES_PASSWORD: ${DB_PASSWORD}
25 volumes:
26 - postgres_data:/var/lib/postgresql/data
27 networks:
28 - keystone
29
30volumes:
31 postgres_data:
32
33networks:
34 keystone:
35 driver: bridge
36EOF
37
38# 2. Create the .env file
39cat > .env << 'EOF'
40DB_NAME=keystone
41DB_USER=keystone
42DB_PASSWORD=changeme
43SESSION_SECRET=your-session-secret
44EOF
45
46# 3. Start the services
47docker compose up -d
48
49# 4. View logs
50docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/keystone-commerce/run | bash

Troubleshooting

  • KeystoneJS fails to start with database connection error: Verify DATABASE_URL format and ensure PostgreSQL container is fully initialized before KeystoneJS starts
  • Admin interface shows 'Session Secret Required' error: Set a strong SESSION_SECRET environment variable with at least 32 characters
  • GraphQL mutations fail with permission errors: Configure access control in your schema.ts lists or create an admin user through the initial setup flow
  • PostgreSQL container exits with 'data directory not empty' error: Remove the postgres_data volume or use different volume name to start fresh
  • KeystoneJS schema changes not reflected: Restart the KeystoneJS container to trigger Prisma migrations and schema updates
  • Memory issues with large product catalogs: Increase PostgreSQL shared_buffers and effective_cache_size through environment variables

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space