docker.recipes

Hono + PostgreSQL

intermediate

Ultrafast web framework for edge and serverless with PostgreSQL.

Overview

Hono is an ultrafast web framework designed specifically for edge computing and serverless environments, built with Web Standard APIs (Request, Response) for maximum portability across JavaScript runtimes including Bun, Deno, Node.js, Cloudflare Workers, and Vercel. Originally created to address the performance limitations of traditional web frameworks in edge environments, Hono features a RegExp-based router that delivers exceptional routing speed while maintaining a small bundle size, making it ideal for latency-sensitive applications deployed at the edge. When combined with PostgreSQL, this stack creates a powerful full-stack solution that leverages PostgreSQL's enterprise-grade ACID compliance, advanced transaction support, and robust JSON/JSONB capabilities alongside Hono's edge-optimized performance characteristics. The PostgreSQL integration provides reliable data persistence with full-text search, geospatial capabilities through PostGIS, and sophisticated query optimization, while Hono handles high-throughput request processing with minimal cold start times. This combination is particularly valuable for developers building modern web applications that require both edge performance and enterprise-grade database capabilities, such as real-time APIs, serverless backends, and globally distributed applications that need consistent data integrity across multiple regions.

Key Features

  • RegExp-based ultrafast routing with sub-millisecond request processing optimized for edge deployment
  • Web Standard API compatibility enabling deployment across Bun, Deno, Node.js, Cloudflare Workers, and Vercel without code changes
  • PostgreSQL ACID compliance with advanced transaction isolation levels for enterprise-grade data integrity
  • JSON/JSONB native support in PostgreSQL for hybrid relational-document data models with indexing
  • Edge-optimized cold start performance with minimal bundle size for serverless environments
  • Full-text search capabilities with ranking and highlighting through PostgreSQL's built-in search functions
  • Logical and streaming replication support for multi-region PostgreSQL deployments
  • Extensible PostgreSQL type system supporting custom functions and PostGIS geospatial operations

Common Use Cases

  • 1Edge-deployed API backends for mobile applications requiring sub-100ms response times globally
  • 2Serverless e-commerce platforms needing ACID transactions for payment processing with edge caching
  • 3Real-time analytics dashboards processing high-frequency data with PostgreSQL window functions
  • 4Multi-tenant SaaS applications leveraging PostgreSQL row-level security and Hono's lightweight routing
  • 5Geospatial applications combining PostGIS capabilities with edge-optimized API responses
  • 6JAMstack applications requiring fast API routes with complex relational data queries
  • 7IoT data collection systems processing sensor data at edge locations with PostgreSQL time-series optimization

Prerequisites

  • Docker Desktop or Docker Engine with Docker Compose v2.0+ installed and running
  • Minimum 1GB RAM available (256MB for PostgreSQL, additional memory for Hono application)
  • Port 3000 available for Hono web server access
  • Basic understanding of JavaScript/TypeScript and SQL query syntax
  • Familiarity with ORM tools like Drizzle or Prisma for database schema management
  • Environment variables configured for DB_NAME, DB_USER, and DB_PASSWORD

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 hono:
3 build: .
4 container_name: hono
5 environment:
6 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
7 ports:
8 - "3000:3000"
9 depends_on:
10 - postgres
11 networks:
12 - hono-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 - hono-network
24
25volumes:
26 postgres_data:
27
28networks:
29 hono-network:
30 driver: bridge

.env Template

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

Usage Notes

  1. 1Docs: https://hono.dev/
  2. 2Access at http://localhost:3000
  3. 3Runs on Bun, Deno, Node.js, Cloudflare Workers, Vercel
  4. 4Web Standard APIs (Request, Response)
  5. 5Ultrafast routing with RegExp-based router
  6. 6Use Drizzle or Prisma for database access

Individual Services(2 services)

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

hono
hono:
  build: .
  container_name: hono
  environment:
    DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
  ports:
    - "3000:3000"
  depends_on:
    - postgres
  networks:
    - hono-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:
    - hono-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 hono:
5 build: .
6 container_name: hono
7 environment:
8 DATABASE_URL: postgresql://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
9 ports:
10 - "3000:3000"
11 depends_on:
12 - postgres
13 networks:
14 - hono-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 - hono-network
26
27volumes:
28 postgres_data:
29
30networks:
31 hono-network:
32 driver: bridge
33EOF
34
35# 2. Create the .env file
36cat > .env << 'EOF'
37DB_NAME=hono
38DB_USER=hono
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/hono-postgres/run | bash

Troubleshooting

  • Connection refused on port 3000: Ensure Hono container built successfully and DATABASE_URL environment variable is properly formatted
  • PostgreSQL connection timeout: Verify postgres container is fully initialized before Hono starts, consider adding healthcheck or wait script
  • FATAL: database does not exist: Check DB_NAME environment variable matches POSTGRES_DB value in postgres service
  • Hono runtime errors about missing dependencies: Verify your Dockerfile includes proper package.json and node_modules installation for chosen runtime
  • ORM connection pooling issues: Configure connection pool size appropriately for PostgreSQL max_connections setting in high-load scenarios
  • Edge deployment failures: Ensure Hono application uses only Web Standard APIs and avoid Node.js-specific modules for serverless compatibility

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