docker.recipes

Echo + PostgreSQL

intermediate

High-performance minimalist Go web framework with PostgreSQL.

Overview

Echo is a high-performance, minimalist web framework for Go that emphasizes speed and simplicity. Created by Vishal Rana in 2015, Echo has become one of the most popular Go web frameworks due to its lightweight design, achieving over 10x faster performance than many alternatives while maintaining an intuitive API. The framework provides essential web server features including routing, middleware support, template rendering, and automatic TLS, making it ideal for building REST APIs, microservices, and web applications that require minimal overhead and maximum throughput. This stack pairs Echo's lightning-fast HTTP handling with PostgreSQL's robust relational database capabilities, creating a powerful foundation for data-driven Go applications. Echo's built-in JSON binding and validation work exceptionally well with PostgreSQL's JSONB support, while the framework's middleware system complements PostgreSQL's transaction management for building secure, scalable applications. The combination leverages Go's compiled performance with PostgreSQL's ACID compliance and advanced querying capabilities. Developers building modern web APIs, SaaS platforms, or high-traffic applications will find this stack particularly valuable. Startups requiring rapid development cycles benefit from Echo's minimal boilerplate and PostgreSQL's flexible schema evolution, while enterprises appreciate the proven reliability of PostgreSQL combined with Go's excellent concurrency handling. This combination is especially suited for teams transitioning from Node.js or Python frameworks who want compiled language performance without sacrificing development velocity.

Key Features

  • Echo's optimized HTTP router with radix tree implementation for sub-microsecond route matching
  • Built-in HTTP/2 server support with automatic protocol negotiation and server push capabilities
  • Native WebSocket support with Echo's context binding for real-time applications
  • PostgreSQL JSONB integration for hybrid relational-document data models
  • Echo middleware chain with PostgreSQL connection pooling for optimal database performance
  • Automatic Let's Encrypt TLS certificate provisioning and renewal
  • PostgreSQL's advanced indexing (GIN, GiST, BRIN) optimized for Echo's query patterns
  • Built-in request validation and binding that maps directly to PostgreSQL constraints

Common Use Cases

  • 1High-throughput REST APIs serving mobile applications with complex relational data requirements
  • 2Real-time analytics dashboards using Echo's WebSocket support and PostgreSQL's window functions
  • 3Multi-tenant SaaS platforms leveraging PostgreSQL's row-level security and Echo's JWT middleware
  • 4E-commerce backends requiring ACID transactions for order processing and inventory management
  • 5Geospatial applications using PostGIS extension with Echo's JSON response optimization
  • 6Microservices architecture where individual services need both performance and data consistency
  • 7Content management systems requiring full-text search capabilities and rapid content delivery

Prerequisites

  • Go 1.19 or higher installed for building Echo applications and dependency management
  • Minimum 1GB RAM for PostgreSQL optimal performance with connection pooling
  • Port 1323 available for Echo web server and port 5432 for PostgreSQL connections
  • Understanding of Go modules, goroutines, and interface-based programming patterns
  • Familiarity with SQL and PostgreSQL-specific features like JSONB and array types
  • Knowledge of HTTP middleware concepts and RESTful API design principles

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

.env Template

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

Usage Notes

  1. 1Docs: https://echo.labstack.com/docs
  2. 2Access at http://localhost:1323
  3. 3Automatic TLS with Let's Encrypt
  4. 4HTTP/2 and WebSocket support
  5. 5Use GORM or sqlx for database access
  6. 6Built-in middleware: logger, recover, cors, jwt

Individual Services(2 services)

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

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

Quick Start

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

Troubleshooting

  • Echo server fails to start with 'bind: address already in use': Check if port 1323 is occupied using 'netstat -tulpn | grep 1323' and stop conflicting services
  • PostgreSQL connection refused errors: Verify postgres container is healthy with 'docker-compose ps' and check DATABASE_URL environment variable format
  • Echo application crashes with 'driver: bad connection': Implement connection retry logic in your Go code and verify PostgreSQL container startup order with depends_on
  • High memory usage in PostgreSQL container: Tune shared_buffers and work_mem in postgresql.conf, typically 25% of available RAM for shared_buffers
  • Echo middleware panics on database operations: Wrap database calls in Echo's error handling middleware and implement proper context cancellation
  • Slow query performance: Enable PostgreSQL query logging with log_statement='all' and use EXPLAIN ANALYZE to optimize queries and add appropriate indexes

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