Mattermost + PostgreSQL + Elasticsearch
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:latest4 environment: 5 - TZ=UTC6 - MM_SQLSETTINGS_DRIVERNAME=postgres7 - MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable8 - MM_ELASTICSEARCHSETTINGS_ENABLEINDEXING=true9 - MM_ELASTICSEARCHSETTINGS_ENABLESEARCHING=true10 - MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:920011 - MM_SERVICESETTINGS_SITEURL=http://localhost12 - MM_FILESETTINGS_DIRECTORY=/mattermost/data13 volumes: 14 - mattermost-data:/mattermost/data15 - mattermost-logs:/mattermost/logs16 - mattermost-config:/mattermost/config17 - mattermost-plugins:/mattermost/plugins18 ports: 19 - "8065:8065"20 depends_on: 21 - postgres22 - elasticsearch23 networks: 24 - mattermost-network25 restart: unless-stopped2627 postgres: 28 image: postgres:1529 environment: 30 - POSTGRES_USER=${POSTGRES_USER}31 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}32 - POSTGRES_DB=mattermost33 volumes: 34 - postgres-data:/var/lib/postgresql/data35 networks: 36 - mattermost-network37 restart: unless-stopped3839 elasticsearch: 40 image: elasticsearch:7.17.1041 environment: 42 - discovery.type=single-node43 - ES_JAVA_OPTS=-Xms512m -Xmx512m44 volumes: 45 - es-data:/usr/share/elasticsearch/data46 networks: 47 - mattermost-network48 restart: unless-stopped4950 nginx: 51 image: nginx:alpine52 volumes: 53 - ./nginx.conf:/etc/nginx/nginx.conf:ro54 ports: 55 - "80:80"56 - "443:443"57 depends_on: 58 - mattermost59 networks: 60 - mattermost-network61 restart: unless-stopped6263volumes: 64 mattermost-data: 65 mattermost-logs: 66 mattermost-config: 67 mattermost-plugins: 68 postgres-data: 69 es-data: 7071networks: 72 mattermost-network: 73 driver: bridge.env Template
.env
1# Mattermost2POSTGRES_USER=mattermost3POSTGRES_PASSWORD=secure_postgres_password45# Site URL for proper linking6MM_SERVICESETTINGS_SITEURL=http://localhostUsage Notes
- 1Mattermost at http://localhost:8065
- 2Create first admin on signup
- 3Elasticsearch for advanced search
- 4Enable plugins in System Console
- 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 file2cat > docker-compose.yml << 'EOF'3services:4 mattermost:5 image: mattermost/mattermost-enterprise-edition:latest6 environment:7 - TZ=UTC8 - MM_SQLSETTINGS_DRIVERNAME=postgres9 - MM_SQLSETTINGS_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/mattermost?sslmode=disable10 - MM_ELASTICSEARCHSETTINGS_ENABLEINDEXING=true11 - MM_ELASTICSEARCHSETTINGS_ENABLESEARCHING=true12 - MM_ELASTICSEARCHSETTINGS_CONNECTIONURL=http://elasticsearch:920013 - MM_SERVICESETTINGS_SITEURL=http://localhost14 - MM_FILESETTINGS_DIRECTORY=/mattermost/data15 volumes:16 - mattermost-data:/mattermost/data17 - mattermost-logs:/mattermost/logs18 - mattermost-config:/mattermost/config19 - mattermost-plugins:/mattermost/plugins20 ports:21 - "8065:8065"22 depends_on:23 - postgres24 - elasticsearch25 networks:26 - mattermost-network27 restart: unless-stopped2829 postgres:30 image: postgres:1531 environment:32 - POSTGRES_USER=${POSTGRES_USER}33 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}34 - POSTGRES_DB=mattermost35 volumes:36 - postgres-data:/var/lib/postgresql/data37 networks:38 - mattermost-network39 restart: unless-stopped4041 elasticsearch:42 image: elasticsearch:7.17.1043 environment:44 - discovery.type=single-node45 - ES_JAVA_OPTS=-Xms512m -Xmx512m46 volumes:47 - es-data:/usr/share/elasticsearch/data48 networks:49 - mattermost-network50 restart: unless-stopped5152 nginx:53 image: nginx:alpine54 volumes:55 - ./nginx.conf:/etc/nginx/nginx.conf:ro56 ports:57 - "80:80"58 - "443:443"59 depends_on:60 - mattermost61 networks:62 - mattermost-network63 restart: unless-stopped6465volumes:66 mattermost-data:67 mattermost-logs:68 mattermost-config:69 mattermost-plugins:70 postgres-data:71 es-data:7273networks:74 mattermost-network:75 driver: bridge76EOF7778# 2. Create the .env file79cat > .env << 'EOF'80# Mattermost81POSTGRES_USER=mattermost82POSTGRES_PASSWORD=secure_postgres_password8384# Site URL for proper linking85MM_SERVICESETTINGS_SITEURL=http://localhost86EOF8788# 3. Start the services89docker compose up -d9091# 4. View logs92docker compose logs -fOne-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 | bashTroubleshooting
- 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
Components
mattermostpostgresqlelasticsearchnginx
Tags
#mattermost#chat#team-communication#slack-alternative
Category
Message Queues & BrokersAd Space
Shortcuts: C CopyF FavoriteD Download