docker.recipes

Mattermost + PostgreSQL + Elasticsearch

intermediate

Self-hosted Slack alternative with enterprise features.

Overview

Mattermost is an open-source team collaboration platform that provides Slack-like messaging, file sharing, and communication features while maintaining full control over your data. Originally developed by SpinPunch in 2015, Mattermost has evolved into a comprehensive team communication solution that prioritizes security, compliance, and self-hosting capabilities. Unlike cloud-based alternatives, Mattermost allows organizations to deploy messaging infrastructure on their own servers, making it ideal for companies with strict data governance requirements or those operating in regulated industries. This stack combines Mattermost with PostgreSQL for robust data storage, Elasticsearch for advanced search capabilities, and NGINX for reverse proxy functionality. PostgreSQL provides ACID-compliant transaction support and handles Mattermost's complex relational data requirements including user management, channel permissions, and message threading. Elasticsearch enables enterprise-grade search features across messages, files, and user content with real-time indexing and relevance scoring. NGINX acts as the web server and reverse proxy, handling SSL termination, load balancing, and serving static assets efficiently. This combination is particularly valuable for organizations needing enterprise-grade team communication with advanced search, audit trails, and compliance features. The stack supports everything from small development teams to large enterprises with thousands of users, while maintaining the flexibility to integrate with existing authentication systems, custom plugins, and third-party tools through Mattermost's extensive API ecosystem.

Key Features

  • Advanced message search with Elasticsearch full-text indexing and relevance scoring
  • PostgreSQL-backed user authentication with support for LDAP, SAML, and OAuth integration
  • Real-time messaging with WebSocket connections proxied through NGINX
  • File sharing and preview capabilities with metadata stored in PostgreSQL
  • Thread-based conversations with PostgreSQL ensuring message relationship integrity
  • Elasticsearch-powered channel and user discovery across large deployments
  • NGINX SSL termination with HTTP/2 support for improved mobile app performance
  • Plugin marketplace with custom integrations stored and managed via PostgreSQL

Common Use Cases

  • 1Enterprise teams requiring on-premises chat with compliance and audit logging
  • 2Development teams needing GitHub, GitLab, and Jenkins integrations with searchable history
  • 3Remote organizations wanting Slack-like features without vendor lock-in
  • 4Healthcare or financial institutions requiring HIPAA or SOX compliant messaging
  • 5Open-source projects needing community communication with extensive search capabilities
  • 6Companies migrating from Slack who want to maintain chat history and integrations
  • 7Educational institutions providing secure student and faculty communication platforms

Prerequisites

  • Minimum 4GB RAM (2GB for Elasticsearch, 1GB for PostgreSQL, 1GB for Mattermost)
  • Docker Engine 20.10+ and Docker Compose 2.0+ installed
  • Ports 80, 443, and 8065 available on the host system
  • Basic understanding of NGINX configuration for SSL certificate setup
  • At least 20GB available disk space for PostgreSQL and Elasticsearch data
  • Knowledge of Mattermost System Console for initial team and user configuration

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 mattermost:
3 image: mattermost/mattermost-enterprise-edition:latest
4 environment:
5 - TZ=UTC
6 - MM_SQLSETTINGS_DRIVERNAME=postgres
7 - MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable
8 - MM_ELASTICSEARCHSETTINGS_ENABLEINDEXING=true
9 - MM_ELASTICSEARCHSETTINGS_ENABLESEARCHING=true
10 - MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:9200
11 - MM_SERVICESETTINGS_SITEURL=http://localhost
12 - MM_FILESETTINGS_DIRECTORY=/mattermost/data
13 volumes:
14 - mattermost-data:/mattermost/data
15 - mattermost-logs:/mattermost/logs
16 - mattermost-config:/mattermost/config
17 - mattermost-plugins:/mattermost/plugins
18 ports:
19 - "8065:8065"
20 depends_on:
21 - postgres
22 - elasticsearch
23 networks:
24 - mattermost-network
25 restart: unless-stopped
26
27 postgres:
28 image: postgres:15
29 environment:
30 - POSTGRES_USER=${POSTGRES_USER}
31 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
32 - POSTGRES_DB=mattermost
33 volumes:
34 - postgres-data:/var/lib/postgresql/data
35 networks:
36 - mattermost-network
37 restart: unless-stopped
38
39 elasticsearch:
40 image: elasticsearch:7.17.10
41 environment:
42 - discovery.type=single-node
43 - ES_JAVA_OPTS=-Xms512m -Xmx512m
44 volumes:
45 - es-data:/usr/share/elasticsearch/data
46 networks:
47 - mattermost-network
48 restart: unless-stopped
49
50 nginx:
51 image: nginx:alpine
52 volumes:
53 - ./nginx.conf:/etc/nginx/nginx.conf:ro
54 ports:
55 - "80:80"
56 - "443:443"
57 depends_on:
58 - mattermost
59 networks:
60 - mattermost-network
61 restart: unless-stopped
62
63volumes:
64 mattermost-data:
65 mattermost-logs:
66 mattermost-config:
67 mattermost-plugins:
68 postgres-data:
69 es-data:
70
71networks:
72 mattermost-network:
73 driver: bridge

.env Template

.env
1# Mattermost
2POSTGRES_USER=mattermost
3POSTGRES_PASSWORD=secure_postgres_password
4
5# Site URL for proper linking
6MM_SERVICESETTINGS_SITEURL=http://localhost

Usage Notes

  1. 1Mattermost at http://localhost:8065
  2. 2Create first admin on signup
  3. 3Elasticsearch for advanced search
  4. 4Enable plugins in System Console
  5. 5Mobile apps available

Individual Services(4 services)

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

mattermost
mattermost:
  image: mattermost/mattermost-enterprise-edition:latest
  environment:
    - TZ=UTC
    - MM_SQLSETTINGS_DRIVERNAME=postgres
    - MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable
    - MM_ELASTICSEARCHSETTINGS_ENABLEINDEXING=true
    - MM_ELASTICSEARCHSETTINGS_ENABLESEARCHING=true
    - MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:9200
    - MM_SERVICESETTINGS_SITEURL=http://localhost
    - MM_FILESETTINGS_DIRECTORY=/mattermost/data
  volumes:
    - mattermost-data:/mattermost/data
    - mattermost-logs:/mattermost/logs
    - mattermost-config:/mattermost/config
    - mattermost-plugins:/mattermost/plugins
  ports:
    - "8065:8065"
  depends_on:
    - postgres
    - elasticsearch
  networks:
    - mattermost-network
  restart: unless-stopped
postgres
postgres:
  image: postgres:15
  environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=mattermost
  volumes:
    - postgres-data:/var/lib/postgresql/data
  networks:
    - mattermost-network
  restart: unless-stopped
elasticsearch
elasticsearch:
  image: elasticsearch:7.17.10
  environment:
    - discovery.type=single-node
    - ES_JAVA_OPTS=-Xms512m -Xmx512m
  volumes:
    - es-data:/usr/share/elasticsearch/data
  networks:
    - mattermost-network
  restart: unless-stopped
nginx
nginx:
  image: nginx:alpine
  volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
  ports:
    - "80:80"
    - "443:443"
  depends_on:
    - mattermost
  networks:
    - mattermost-network
  restart: unless-stopped

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 mattermost:
5 image: mattermost/mattermost-enterprise-edition:latest
6 environment:
7 - TZ=UTC
8 - MM_SQLSETTINGS_DRIVERNAME=postgres
9 - MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable
10 - MM_ELASTICSEARCHSETTINGS_ENABLEINDEXING=true
11 - MM_ELASTICSEARCHSETTINGS_ENABLESEARCHING=true
12 - MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:9200
13 - MM_SERVICESETTINGS_SITEURL=http://localhost
14 - MM_FILESETTINGS_DIRECTORY=/mattermost/data
15 volumes:
16 - mattermost-data:/mattermost/data
17 - mattermost-logs:/mattermost/logs
18 - mattermost-config:/mattermost/config
19 - mattermost-plugins:/mattermost/plugins
20 ports:
21 - "8065:8065"
22 depends_on:
23 - postgres
24 - elasticsearch
25 networks:
26 - mattermost-network
27 restart: unless-stopped
28
29 postgres:
30 image: postgres:15
31 environment:
32 - POSTGRES_USER=${POSTGRES_USER}
33 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
34 - POSTGRES_DB=mattermost
35 volumes:
36 - postgres-data:/var/lib/postgresql/data
37 networks:
38 - mattermost-network
39 restart: unless-stopped
40
41 elasticsearch:
42 image: elasticsearch:7.17.10
43 environment:
44 - discovery.type=single-node
45 - ES_JAVA_OPTS=-Xms512m -Xmx512m
46 volumes:
47 - es-data:/usr/share/elasticsearch/data
48 networks:
49 - mattermost-network
50 restart: unless-stopped
51
52 nginx:
53 image: nginx:alpine
54 volumes:
55 - ./nginx.conf:/etc/nginx/nginx.conf:ro
56 ports:
57 - "80:80"
58 - "443:443"
59 depends_on:
60 - mattermost
61 networks:
62 - mattermost-network
63 restart: unless-stopped
64
65volumes:
66 mattermost-data:
67 mattermost-logs:
68 mattermost-config:
69 mattermost-plugins:
70 postgres-data:
71 es-data:
72
73networks:
74 mattermost-network:
75 driver: bridge
76EOF
77
78# 2. Create the .env file
79cat > .env << 'EOF'
80# Mattermost
81POSTGRES_USER=mattermost
82POSTGRES_PASSWORD=secure_postgres_password
83
84# Site URL for proper linking
85MM_SERVICESETTINGS_SITEURL=http://localhost
86EOF
87
88# 3. Start the services
89docker compose up -d
90
91# 4. View logs
92docker 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/mattermost-complete/run | bash

Troubleshooting

  • Elasticsearch fails to start with 'max virtual memory areas vm.max_map_count too low': Run 'sudo sysctl -w vm.max_map_count=262144' on the host
  • Mattermost shows database connection errors: Verify POSTGRES_USER and POSTGRES_PASSWORD environment variables match between services
  • Search functionality not working in Mattermost: Check Elasticsearch container logs and ensure MM_ELASTICSEARCHSETTINGS_* variables are properly configured
  • NGINX returns 502 Bad Gateway errors: Confirm Mattermost container is running and accessible on port 8065 within the Docker network
  • PostgreSQL container exits with 'database system was shut down': Check available disk space and ensure postgres-data volume has proper permissions
  • Mattermost plugins fail to install: Verify mattermost-plugins volume is mounted and container has write permissions to /mattermost/plugins

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