docker.recipes

RedwoodJS + PostgreSQL

intermediate

Full-stack React framework with GraphQL API and PostgreSQL.

Overview

RedwoodJS is a full-stack JavaScript framework that combines React for the frontend with a Node.js API backend, all unified through GraphQL and convention-over-configuration principles. Created by Tom Preston-Werner (GitHub co-founder) in 2020, Redwood aims to bring Ruby on Rails-style productivity to the JavaScript ecosystem by providing opinionated project structure, automatic code generation, and batteries-included tooling. The framework uses Prisma as its ORM and comes with built-in authentication, testing frameworks, and deployment patterns. This RedwoodJS and PostgreSQL combination creates a production-ready full-stack application environment where PostgreSQL serves as the primary database backend through Prisma's type-safe query layer. RedwoodJS automatically generates GraphQL resolvers and TypeScript types based on your Prisma schema, while PostgreSQL provides enterprise-grade data integrity, complex querying capabilities, and JSON support for flexible data models. The framework's 'Cells' pattern handles loading states and error boundaries declaratively, making database-driven UI components remarkably simple to implement. This stack is ideal for teams wanting rapid full-stack development without sacrificing type safety or scalability. Startups building SaaS applications benefit from Redwood's scaffolding commands that generate complete CRUD interfaces in minutes, while enterprises appreciate PostgreSQL's ACID compliance and mature ecosystem. The combination particularly shines for applications requiring complex business logic, user authentication, and real-time features, as RedwoodJS includes built-in support for subscriptions and background jobs.

Key Features

  • Full-stack TypeScript with automatic type generation from Prisma schema to GraphQL resolvers
  • Cells pattern for declarative data fetching with built-in loading, error, and success states
  • Automatic GraphQL API generation with CRUD operations based on Prisma models
  • Built-in code generators for pages, components, services, and complete scaffold operations
  • PostgreSQL JSON/JSONB support through Prisma for flexible schema evolution
  • Integrated authentication system with multiple providers and role-based access control
  • Database migration system with Prisma Migrate for version-controlled schema changes
  • Built-in testing framework with database seeding and transaction rollback between tests

Common Use Cases

  • 1SaaS applications requiring user authentication, subscription management, and complex business logic
  • 2E-commerce platforms with product catalogs, inventory tracking, and order processing workflows
  • 3Content management systems with role-based publishing and media asset organization
  • 4Enterprise dashboards displaying real-time analytics from PostgreSQL's analytical functions
  • 5Multi-tenant applications using PostgreSQL's row-level security and schema isolation
  • 6API-first applications where RedwoodJS serves multiple frontend clients through GraphQL
  • 7Rapid prototype development leveraging scaffold generators for quick CRUD interface creation

Prerequisites

  • Docker and Docker Compose installed with minimum 2GB RAM allocated to containers
  • Node.js 18+ knowledge and familiarity with React hooks and modern JavaScript
  • Basic understanding of GraphQL queries, mutations, and schema definition language
  • PostgreSQL fundamentals including SQL queries, indexes, and migration concepts
  • Port 8910 available for RedwoodJS development server access
  • Experience with Prisma ORM schema syntax and migration workflow

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 redwood:
3 build: .
4 container_name: redwood
5 environment:
6 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
7 ports:
8 - "8910:8910"
9 depends_on:
10 - postgres
11 networks:
12 - redwood-network
13
14 postgres:
15 image: postgres:16-alpine
16 environment:
17 POSTGRES_DB: ${DB_NAME}
18 POSTGRES_USER: ${DB_USER}
19 POSTGRES_PASSWORD: ${DB_PASSWORD}
20 volumes:
21 - postgres_data:/var/lib/postgresql/data
22 networks:
23 - redwood-network
24
25volumes:
26 postgres_data:
27
28networks:
29 redwood-network:
30 driver: bridge

.env Template

.env
1DB_NAME=redwood
2DB_USER=redwood
3DB_PASSWORD=changeme

Usage Notes

  1. 1Docs: https://redwoodjs.com/docs
  2. 2Access at http://localhost:8910
  3. 3Built-in GraphQL API layer
  4. 4Cells: declarative data fetching components
  5. 5Prisma for database, automatic CRUD scaffolding
  6. 6yarn rw db migrate to run migrations

Individual Services(2 services)

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

redwood
redwood:
  build: .
  container_name: redwood
  environment:
    DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
  ports:
    - "8910:8910"
  depends_on:
    - postgres
  networks:
    - redwood-network
postgres
postgres:
  image: postgres:16-alpine
  environment:
    POSTGRES_DB: ${DB_NAME}
    POSTGRES_USER: ${DB_USER}
    POSTGRES_PASSWORD: ${DB_PASSWORD}
  volumes:
    - postgres_data:/var/lib/postgresql/data
  networks:
    - redwood-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 redwood:
5 build: .
6 container_name: redwood
7 environment:
8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
9 ports:
10 - "8910:8910"
11 depends_on:
12 - postgres
13 networks:
14 - redwood-network
15
16 postgres:
17 image: postgres:16-alpine
18 environment:
19 POSTGRES_DB: ${DB_NAME}
20 POSTGRES_USER: ${DB_USER}
21 POSTGRES_PASSWORD: ${DB_PASSWORD}
22 volumes:
23 - postgres_data:/var/lib/postgresql/data
24 networks:
25 - redwood-network
26
27volumes:
28 postgres_data:
29
30networks:
31 redwood-network:
32 driver: bridge
33EOF
34
35# 2. Create the .env file
36cat > .env << 'EOF'
37DB_NAME=redwood
38DB_USER=redwood
39DB_PASSWORD=changeme
40EOF
41
42# 3. Start the services
43docker compose up -d
44
45# 4. View logs
46docker 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/redwood-postgres/run | bash

Troubleshooting

  • Error: 'relation does not exist' on startup: Run `yarn rw prisma migrate dev` inside the redwood container to create database tables
  • GraphQL playground shows connection refused: Ensure DATABASE_URL environment variable matches PostgreSQL connection string format exactly
  • RedwoodJS build fails with Prisma generation errors: Delete node_modules and run `yarn install && yarn rw prisma generate` to rebuild client
  • Database connection timeout on container restart: Add `restart: unless-stopped` to postgres service and verify network connectivity between services
  • Hot reload not working in development: Ensure the redwood container has proper file system access and CHOKIDAR_USEPOLLING=true if on Windows/WSL
  • Prisma migrate fails with permission denied: Check that POSTGRES_USER has sufficient privileges or connect as superuser for initial schema creation

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