Self-host Discourse with Docker Compose
Plataforma de foros de discusión para crear y moderar una comunidad en línea.
discourse
axllent/mailpit:v1.22
postgres
pgvector/pgvector:pg16
postgres-postgres-data-init
busybox
postgres-postgres-socket-init
busybox
redis
redis:7
redis-redis-data-init
busybox
The steps below take a few minutes end to end.
Requirements
You'll need these installed on the machine you're deploying to:
Docker
Packages Discourse and everything it depends on into an isolated container, so it runs the same way on your machine as it does everywhere else.
Install guideDocker Compose
Reads docker-compose.yml and starts everything in it together. Ships with Docker Desktop. On Linux servers it's usually a separate install.
Install guide1. Docker compose setup and file
Create a folder for Discourse and save the file below into it as docker-compose.yml. It describes every container the stack needs — Discourse itself and any supporting services, such as its database — along with the ports, volumes and environment variables each one uses. You'll also need an empty .env file in the same folder; Docker Compose reads it automatically and uses it to fill in the ${VARIABLE} references you'll see in the file below.
docker-compose.yml
version: "3.9"
services:
discourse:
image: discourse/discourse:2026.11.0-latest.1
restart: unless-stopped
ports:
- 3000:3000
environment:
BASE_URL: http://discourse.localhost:3000
DISCOURSE_DB_HOST: localhost
DISCOURSE_DB_NAME: discourse
DISCOURSE_DB_PASSWORD: ${RANDOM_DISCOURSE_PG_PASSWORD}
DISCOURSE_DB_PORT: "5432"
DISCOURSE_DB_USERNAME: postgres
DISCOURSE_DEVELOPER_EMAILS: changeme@bitflake.com
DISCOURSE_HOSTNAME: discourse.localhost
DISCOURSE_LOAD_MINI_PROFILER: "false"
DISCOURSE_MAX_ASSET_REQS_PER_IP_PER_10_SECONDS: "2000"
DISCOURSE_MAX_REQS_PER_IP_PER_10_SECONDS: "1000"
DISCOURSE_MAX_REQS_PER_IP_PER_MINUTE: "6000"
DISCOURSE_NOTIFICATION_EMAIL: noreply+discourse@mail.bitflake.cloud
DISCOURSE_REDIS_HOST: redis
DISCOURSE_REDIS_PASSWORD: ${RANDOM_REDIS_PASSWORD}
DISCOURSE_REDIS_PORT: "6379"
DISCOURSE_SECRET_KEY_BASE: ${RANDOM_DISCOURSE_SECRET_KEY_BASE}
DISCOURSE_SERVE_STATIC_ASSETS: "true"
DISCOURSE_SMTP_ADDRESS: mail
DISCOURSE_SMTP_PORT: "1025"
LANG: en_US.UTF-8
LANGUAGE: en_US.UTF-8
LC_ALL: en_US.UTF-8
UNICORN_BIND_ALL: "1"
volumes:
- shared:/shared
- generated-assets:/var/www/discourse/app/assets/generated
- public-plugins:/var/www/discourse/public/plugins
- public-assets:/var/www/discourse/public/assets
- rails-tmp:/var/www/discourse/tmp
- rails-log:/var/www/discourse/log
- tmp:/tmp
configs:
- source: discourse-discourse-start.sh
target: /etc/bflk/discourse-start.sh
depends_on:
redis:
condition: service_started
entrypoint:
- /bin/bash
- /etc/bflk/discourse-start.sh
mail:
image: axllent/mailpit:v1.22
restart: unless-stopped
postgres:
image: pgvector/pgvector:pg16
restart: unless-stopped
network_mode: service:discourse
environment:
POSTGRES_DB: discourse
POSTGRES_PASSWORD: ${RANDOM_DISCOURSE_PG_PASSWORD}
POSTGRES_USER: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
- postgres-socket:/var/run/postgresql
depends_on:
discourse:
condition: service_started
postgres-postgres-data-init:
condition: service_completed_successfully
postgres-postgres-socket-init:
condition: service_completed_successfully
postgres-postgres-data-init:
image: busybox
volumes:
- postgres-data:/var/lib/postgresql/data
command:
- chown
- 999:999
- /var/lib/postgresql/data
postgres-postgres-socket-init:
image: busybox
volumes:
- postgres-socket:/var/run/postgresql
command:
- chown
- 999:999
- /var/run/postgresql
redis:
image: redis:7
restart: unless-stopped
environment:
REDIS_PASSWORD: ${RANDOM_REDIS_PASSWORD}
volumes:
- redis-data:/data
depends_on:
redis-redis-data-init:
condition: service_completed_successfully
entrypoint:
- sh
- -c
command:
- redis-server --requirepass $$REDIS_PASSWORD
redis-redis-data-init:
image: busybox
volumes:
- redis-data:/data
command:
- chown
- 999:999
- /data
volumes:
generated-assets: null
postgres-data: null
postgres-socket: null
public-assets: null
public-plugins: null
rails-log: null
rails-tmp: null
redis-data: null
shared: null
tmp: null
configs:
discourse-discourse-start.sh:
content: |
set -e
cd /var/www/discourse
mkdir -p /shared/uploads /shared/backups /shared/log/rails
export HOME=/tmp
bundle exec rake db:migrate
bundle exec rails runner '
SiteSetting.notification_email = ENV.fetch("DISCOURSE_NOTIFICATION_EMAIL")
SiteSetting.force_https = ENV.fetch("BASE_URL").start_with?("https://")
'
SKIP_EMBER_CLI_COMPILE=1 bundle exec rake assets:precompile
LD_PRELOAD=$$RUBY_ALLOCATOR exec bundle exec pitchfork -E production -c config/pitchfork.conf.rb
Volumes
Discourse stores its data in named Docker volumes, so it survives container restarts and updates:
- shared mounted at /shared: Discourse's shared data directory: uploaded images and attachments (public/uploads links here) and backups (public/backups links here).
- generated-assets mounted at /var/www/discourse/app/assets/generated: The image's prebuilt frontend bundles. Plugin activation adds symlinks here on every boot, so it must be writable and start with the image's contents.
- public-plugins mounted at /var/www/discourse/public/plugins: Symlinks to each bundled plugin's public files, rewritten on every boot.
- public-assets mounted at /var/www/discourse/public/assets: Compiled CSS and JS, rebuilt by assets:precompile on every boot.
- rails-tmp mounted at /var/www/discourse/tmp: Rails tmp directory: the image's boot cache and prebuilt asset processor, plus pid and lock files.
- rails-log mounted at /var/www/discourse/log: Rails and Sidekiq log files.
- tmp mounted at /tmp: Scratch space for uploads and image processing.
2. Secret generation
Discourse needs a few randomly generated secrets — for example, database passwords or an internal session key — before it can start. These are referenced from docker-compose.yml above but don't live in it, so they need to end up in your .env file. Pick one of the two options below.
Generating secrets…
3. Start Discourse with Docker Compose
From the folder with docker-compose.yml and .env, run:
Terminal
Start Discourse and all its supporting services in the background.
docker compose up -dThe -d flag runs the stack in the background so it keeps running after you close the terminal. Docker will pull the images the first time, which can take a minute or two.
To check on it afterwards: docker compose ps shows whether containers are healthy, and docker compose logs -f follows their logs if something looks wrong. Once it's running, open http://localhost:3000 in your browser.