docker.recipes

Craft CMS

intermediate

Flexible content management with custom fields and matrix blocks.

Overview

Craft CMS is a flexible, developer-friendly content management system built on the Yii PHP framework, designed to give content creators and developers unprecedented control over digital experiences. Unlike rigid, template-based CMS platforms, Craft focuses on structured content with custom fields, matrix blocks for complex layouts, and element relationships that make content truly reusable across different contexts. This stack combines Craft CMS with PostgreSQL and Redis to create a robust, scalable content platform that can handle everything from simple blogs to complex multi-site enterprise deployments. This configuration leverages PostgreSQL's advanced JSON support and ACID compliance to store Craft's flexible content structures while maintaining data integrity across complex field relationships and matrix blocks. Redis provides high-performance session storage and caching, dramatically improving response times for content queries and reducing database load during traffic spikes. The combination allows Craft to scale beyond basic MySQL setups while providing enterprise-grade reliability. This stack is ideal for agencies managing multiple client sites, content-heavy applications requiring custom field architectures, and developers who need a CMS that adapts to their data model rather than forcing predetermined structures. The PostgreSQL foundation makes it particularly valuable for applications requiring complex content relationships, multi-language support, or integration with existing enterprise PostgreSQL infrastructure.

Key Features

  • Matrix fields with PostgreSQL JSON storage for complex, nested content blocks
  • Element relationship queries optimized by PostgreSQL's advanced indexing
  • Redis-powered session management for improved multi-user editing performance
  • Custom field types stored efficiently in PostgreSQL's flexible schema system
  • Content localization using PostgreSQL's full-text search capabilities
  • Redis caching for template rendering and database query optimization
  • Asset transformation pipeline with metadata stored in PostgreSQL
  • GraphQL API powered by PostgreSQL's JSON querying capabilities

Common Use Cases

  • 1Multi-site agency platforms requiring shared content libraries and templates
  • 2Enterprise content hubs with complex approval workflows and user permissions
  • 3E-commerce sites needing flexible product catalogs with custom attributes
  • 4News and publishing platforms with structured article relationships
  • 5Portfolio websites requiring custom project categorization and filtering
  • 6Corporate intranets with document management and employee directories
  • 7Event management platforms with recurring schedules and venue relationships

Prerequisites

  • Docker and Docker Compose installed with minimum 2GB RAM available
  • Composer installed locally for initial Craft project creation
  • Basic understanding of Craft CMS field types and templating with Twig
  • Environment variables configured: DB_PASSWORD and SECURITY_KEY
  • Port 8080 available for web access
  • PostgreSQL knowledge helpful for advanced content queries and optimization

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 craft:
3 image: craftcms/cli:latest
4 container_name: craft
5 restart: unless-stopped
6 environment:
7 CRAFT_DB_DRIVER: pgsql
8 CRAFT_DB_SERVER: postgres
9 CRAFT_DB_DATABASE: craft
10 CRAFT_DB_USER: craft
11 CRAFT_DB_PASSWORD: ${DB_PASSWORD}
12 CRAFT_SECURITY_KEY: ${SECURITY_KEY}
13 volumes:
14 - ./craft:/app
15 ports:
16 - "8080:8080"
17 depends_on:
18 - postgres
19 - redis
20 networks:
21 - craft-network
22
23 postgres:
24 image: postgres:16-alpine
25 container_name: craft-postgres
26 environment:
27 POSTGRES_USER: craft
28 POSTGRES_PASSWORD: ${DB_PASSWORD}
29 POSTGRES_DB: craft
30 volumes:
31 - postgres_data:/var/lib/postgresql/data
32 networks:
33 - craft-network
34
35 redis:
36 image: redis:alpine
37 container_name: craft-redis
38 networks:
39 - craft-network
40
41volumes:
42 postgres_data:
43
44networks:
45 craft-network:
46 driver: bridge

.env Template

.env
1DB_PASSWORD=changeme
2SECURITY_KEY=your-security-key

Usage Notes

  1. 1Docs: https://craftcms.com/docs/
  2. 2Create project first: composer create-project craftcms/craft
  3. 3Access at http://localhost:8080, admin at /admin
  4. 4Matrix fields: nested, repeatable content blocks
  5. 5Element types: entries, categories, users, assets, globals
  6. 6Free Solo license; Pro adds GraphQL, multi-site features

Individual Services(3 services)

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

craft
craft:
  image: craftcms/cli:latest
  container_name: craft
  restart: unless-stopped
  environment:
    CRAFT_DB_DRIVER: pgsql
    CRAFT_DB_SERVER: postgres
    CRAFT_DB_DATABASE: craft
    CRAFT_DB_USER: craft
    CRAFT_DB_PASSWORD: ${DB_PASSWORD}
    CRAFT_SECURITY_KEY: ${SECURITY_KEY}
  volumes:
    - ./craft:/app
  ports:
    - "8080:8080"
  depends_on:
    - postgres
    - redis
  networks:
    - craft-network
postgres
postgres:
  image: postgres:16-alpine
  container_name: craft-postgres
  environment:
    POSTGRES_USER: craft
    POSTGRES_PASSWORD: ${DB_PASSWORD}
    POSTGRES_DB: craft
  volumes:
    - postgres_data:/var/lib/postgresql/data
  networks:
    - craft-network
redis
redis:
  image: redis:alpine
  container_name: craft-redis
  networks:
    - craft-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 craft:
5 image: craftcms/cli:latest
6 container_name: craft
7 restart: unless-stopped
8 environment:
9 CRAFT_DB_DRIVER: pgsql
10 CRAFT_DB_SERVER: postgres
11 CRAFT_DB_DATABASE: craft
12 CRAFT_DB_USER: craft
13 CRAFT_DB_PASSWORD: ${DB_PASSWORD}
14 CRAFT_SECURITY_KEY: ${SECURITY_KEY}
15 volumes:
16 - ./craft:/app
17 ports:
18 - "8080:8080"
19 depends_on:
20 - postgres
21 - redis
22 networks:
23 - craft-network
24
25 postgres:
26 image: postgres:16-alpine
27 container_name: craft-postgres
28 environment:
29 POSTGRES_USER: craft
30 POSTGRES_PASSWORD: ${DB_PASSWORD}
31 POSTGRES_DB: craft
32 volumes:
33 - postgres_data:/var/lib/postgresql/data
34 networks:
35 - craft-network
36
37 redis:
38 image: redis:alpine
39 container_name: craft-redis
40 networks:
41 - craft-network
42
43volumes:
44 postgres_data:
45
46networks:
47 craft-network:
48 driver: bridge
49EOF
50
51# 2. Create the .env file
52cat > .env << 'EOF'
53DB_PASSWORD=changeme
54SECURITY_KEY=your-security-key
55EOF
56
57# 3. Start the services
58docker compose up -d
59
60# 4. View logs
61docker 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/craft-cms/run | bash

Troubleshooting

  • Craft installation error 'could not connect to database': Verify DB_PASSWORD matches in both craft and postgres services
  • Matrix field data not saving: Check PostgreSQL max_allowed_packet size and JSON field limits in database configuration
  • Session timeout issues during content editing: Ensure Redis container is running and accessible on craft-network
  • Asset uploads failing: Verify ./craft directory permissions and volume mount is writable by container user
  • GraphQL queries timing out: Enable PostgreSQL query optimization and add appropriate indexes for content relationships
  • Craft security key errors: Ensure SECURITY_KEY environment variable is set and consistent across container restarts

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

Components

craftpostgresredis

Tags

#craft#php#flexible#custom-fields

Category

CMS & Blogging
Ad Space