docker.recipes

AdonisJS + PostgreSQL

intermediate

Node.js MVC framework with PostgreSQL and Lucid ORM.

Overview

AdonisJS is a TypeScript-first Node.js MVC framework inspired by Laravel and Rails, designed to provide a complete web application development experience with built-in features like authentication, validation, ORM, and mail handling. Created by Harminder Virk, AdonisJS emphasizes developer productivity through convention over configuration, strong typing, and a rich ecosystem of first-party packages that eliminate the need to piece together disparate npm modules. This stack combines AdonisJS with PostgreSQL to create a robust web application platform where Lucid ORM (AdonisJS's built-in ORM) leverages PostgreSQL's advanced features like JSONB columns, full-text search, and complex relationship handling. PostgreSQL's ACID compliance and advanced indexing capabilities complement AdonisJS's sophisticated query builder and migration system, enabling developers to build data-intensive applications with confidence in data integrity and performance. This combination is ideal for development teams seeking a Laravel-like experience in the Node.js ecosystem, particularly those building content management systems, e-commerce platforms, or enterprise applications requiring complex business logic and reliable data persistence. The TypeScript-first approach of AdonisJS paired with PostgreSQL's mature feature set makes this stack particularly valuable for teams prioritizing code maintainability and long-term scalability.

Key Features

  • Lucid ORM with full PostgreSQL feature support including JSONB columns, arrays, and advanced data types
  • Built-in database migrations and schema management with PostgreSQL-specific column types and constraints
  • Edge templating engine with server-side rendering and PostgreSQL query result formatting
  • Integrated authentication system with PostgreSQL session storage and user management
  • Route model binding with automatic PostgreSQL record fetching and type safety
  • Built-in validator with PostgreSQL unique constraint checking and database rule validation
  • AdonisJS ace commands for database seeding, migration rollbacks, and PostgreSQL maintenance tasks
  • Full-text search integration using PostgreSQL's native search capabilities through Lucid ORM

Common Use Cases

  • 1Enterprise web applications requiring complex business logic with reliable ACID-compliant data storage
  • 2Content management systems with mixed relational and JSON document storage needs
  • 3E-commerce platforms needing inventory management, order processing, and financial transaction integrity
  • 4Multi-tenant SaaS applications leveraging PostgreSQL's row-level security and schema isolation
  • 5API backends for mobile applications requiring authentication, file uploads, and real-time features
  • 6Internal business tools and dashboards with complex reporting and data analytics requirements
  • 7Educational platforms with user management, course content delivery, and progress tracking

Prerequisites

  • Docker and Docker Compose installed with at least 1GB RAM available for PostgreSQL
  • Node.js and npm knowledge for AdonisJS application development and package management
  • Basic understanding of MVC architecture patterns and ORM concepts
  • SQL knowledge for database design, migrations, and complex query optimization
  • Port 3333 available for AdonisJS application access
  • Environment file (.env) configuration experience for database credentials and application settings

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 adonis:
3 build: .
4 container_name: adonis
5 environment:
6 DB_CONNECTION: pg
7 PG_HOST: postgres
8 PG_PORT: 5432
9 PG_USER: ${DB_USER}
10 PG_PASSWORD: ${DB_PASSWORD}
11 PG_DB_NAME: ${DB_NAME}
12 ports:
13 - "3333:3333"
14 depends_on:
15 - postgres
16 networks:
17 - adonis-network
18
19 postgres:
20 image: postgres:16-alpine
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 - adonis-network
29
30volumes:
31 postgres_data:
32
33networks:
34 adonis-network:
35 driver: bridge

.env Template

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

Usage Notes

  1. 1Docs: https://docs.adonisjs.com/
  2. 2Access at http://localhost:3333
  3. 3TypeScript-first MVC framework for Node.js
  4. 4Lucid ORM with migrations: node ace migration:run
  5. 5Built-in auth, validation, i18n, and mail
  6. 6Similar developer experience to Laravel/Rails

Individual Services(2 services)

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

adonis
adonis:
  build: .
  container_name: adonis
  environment:
    DB_CONNECTION: pg
    PG_HOST: postgres
    PG_PORT: 5432
    PG_USER: ${DB_USER}
    PG_PASSWORD: ${DB_PASSWORD}
    PG_DB_NAME: ${DB_NAME}
  ports:
    - "3333:3333"
  depends_on:
    - postgres
  networks:
    - adonis-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:
    - adonis-network

Quick Start

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

Troubleshooting

  • Connection refused to PostgreSQL: Ensure postgres service is fully started before adonis container attempts connection, add healthcheck or increase depends_on wait time
  • Migration failed with relation does not exist: Run 'node ace migration:run' inside the adonis container after PostgreSQL is ready and database is created
  • TypeScript compilation errors on startup: Verify AdonisJS version compatibility and ensure all @adonisjs packages are at matching versions in package.json
  • Session/authentication not persisting: Check that PostgreSQL connection is stable and session table migration has been executed successfully
  • Lucid ORM query timeouts: Increase PostgreSQL max_connections setting and optimize queries using AdonisJS query builder explain methods
  • Port 3333 already in use: Stop any existing Node.js applications or change the host port mapping in docker-compose.yml

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