{"slug":"discourse","title":"手把手教你部署Discourse","description":"Discourse是一个开源的强大的论坛系统，让你马上就能拥有自己的BBS","coverImage":"https://b.acofork.com/img/discourse-2025-05-02-22-03-04-image.webp","coverWidth":1363,"coverHeight":916,"date":"2025-05-01","tags":["服务器"],"pinned":false,"wordCount":790,"html":"<h2 id=\"正式开始\">正式开始</h2><p>确保你安装了 <code>Docker</code> 和 <code>Docker-Compose</code> </p>\n<p>选一个目录创建 <code>docker-compose.yml</code></p>\n<p>写入内容</p>\n<div class=\"markdown-code\" data-language=\"yaml\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>yaml</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-yaml\"><span class=\"hljs-attr\">version:</span> <span class=\"hljs-string\">'2'</span>\n<span class=\"hljs-attr\">services:</span>\n  <span class=\"hljs-attr\">postgresql:</span>\n    <span class=\"hljs-attr\">image:</span> <span class=\"hljs-string\">docker.io/bitnami/postgresql:11</span>\n    <span class=\"hljs-attr\">volumes:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">'postgresql_data:/bitnami/postgresql'</span>\n    <span class=\"hljs-attr\">environment:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_POSTGRES_PASSWORD=admin12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_USERNAME=ex_discourse</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_PASSWORD=user12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_DATABASE=example_discourse</span>\n  <span class=\"hljs-attr\">redis:</span>\n    <span class=\"hljs-attr\">image:</span> <span class=\"hljs-string\">docker.io/bitnami/redis:6.0</span>\n    <span class=\"hljs-attr\">environment:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">REDIS_PASSWORD=redis12345</span>\n    <span class=\"hljs-attr\">volumes:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">'redis_data:/bitnami/redis'</span>\n  <span class=\"hljs-attr\">discourse:</span>\n    <span class=\"hljs-attr\">image:</span> <span class=\"hljs-string\">docker.io/bitnami/discourse:2</span>\n    <span class=\"hljs-attr\">ports:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">'127.0.0.1:880:3000'</span>\n    <span class=\"hljs-attr\">volumes:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">'discourse_data:/bitnami/discourse'</span>\n    <span class=\"hljs-attr\">depends_on:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">postgresql</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">redis</span>\n    <span class=\"hljs-attr\">environment:</span>\n      <span class=\"hljs-comment\"># 用户和站点配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_HOST=example.com</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_USERNAME=siteadmin</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_PASSWORD=siteadmin12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_EMAIL=siteadmin@gmail.com</span>\n      <span class=\"hljs-comment\"># 数据库连接配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_HOST=postgresql</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_PORT_NUMBER=5432</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_USER=ex_discourse</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_PASSWORD=user12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_NAME=example_discourse</span>\n      <span class=\"hljs-comment\"># Redis 连接配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_HOST=redis</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_PORT_NUMBER=6379</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_PASSWORD=redis12345</span>\n      <span class=\"hljs-comment\"># 使用 postgresql-client 为 Discourse 创建数据库</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_CLIENT_POSTGRES_USER=postgres</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_CLIENT_POSTGRES_PASSWORD=admin12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_CLIENT_CREATE_DATABASE_NAME=example_discourse</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS=hstore,pg_trgm</span>\n      <span class=\"hljs-comment\"># SMTP</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_HOST=smtp.mailgun.org</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PORT=587</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_USER=邮箱用户名</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PASSWORD=邮箱密码</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PROTOCOL=tls或ssl</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_AUTH=login</span>\n  <span class=\"hljs-attr\">sidekiq:</span>\n    <span class=\"hljs-attr\">image:</span> <span class=\"hljs-string\">docker.io/bitnami/discourse:2</span>\n    <span class=\"hljs-attr\">depends_on:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">discourse</span>\n    <span class=\"hljs-attr\">volumes:</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">'sidekiq_data:/bitnami/discourse'</span>\n    <span class=\"hljs-attr\">command:</span> <span class=\"hljs-string\">/opt/bitnami/scripts/discourse-sidekiq/run.sh</span>\n    <span class=\"hljs-attr\">environment:</span>\n      <span class=\"hljs-comment\"># 用户和站点配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_HOST=example.com</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_USERNAME=siteadmin</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_PASSWORD=siteadmin12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_EMAIL=siteadmin@gmail.com</span>\n      <span class=\"hljs-comment\"># 数据库连接配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_HOST=postgresql</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_PORT_NUMBER=5432</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_USER=ex_discourse</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_PASSWORD=user12345</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_DATABASE_NAME=example_discourse</span>\n      <span class=\"hljs-comment\"># Redis 连接配置</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_HOST=redis</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_PORT_NUMBER=6379</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_REDIS_PASSWORD=redis12345</span>\n      <span class=\"hljs-comment\"># SMTP</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_HOST=smtp.mailgun.org</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PORT=587</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_USER=邮箱用户名</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PASSWORD=邮箱密码</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_PROTOCOL=tls或ssl</span>\n      <span class=\"hljs-bullet\">-</span> <span class=\"hljs-string\">DISCOURSE_SMTP_AUTH=login</span>\n<span class=\"hljs-attr\">volumes:</span>\n  <span class=\"hljs-attr\">postgresql_data:</span>\n    <span class=\"hljs-attr\">driver:</span> <span class=\"hljs-string\">local</span>\n  <span class=\"hljs-attr\">redis_data:</span>\n    <span class=\"hljs-attr\">driver:</span> <span class=\"hljs-string\">local</span>\n  <span class=\"hljs-attr\">discourse_data:</span>\n    <span class=\"hljs-attr\">driver:</span> <span class=\"hljs-string\">local</span>\n  <span class=\"hljs-attr\">sidekiq_data:</span>\n    <span class=\"hljs-attr\">driver:</span> <span class=\"hljs-string\">local</span></code></pre></div><p>需要修改的部分。配置文件中两份都要改</p>\n<table>\n<thead>\n<tr>\n<th>需替换值</th>\n<th>解释</th>\n</tr>\n</thead>\n<tbody><tr>\n<td>admin12345</td>\n<td>数据库管理员密码（可选）</td>\n</tr>\n<tr>\n<td>ex_discourse</td>\n<td>数据库用户名（可选）</td>\n</tr>\n<tr>\n<td>user12345</td>\n<td>数据库用户密码（可选）</td>\n</tr>\n<tr>\n<td>example_discourse</td>\n<td>数据库名（可选）</td>\n</tr>\n<tr>\n<td>redis12345</td>\n<td>Redis 密码（可选）</td>\n</tr>\n<tr>\n<td>127.0.0.1:880</td>\n<td>映射端口（可选）</td>\n</tr>\n<tr>\n<td>example.com</td>\n<td>网站IP或域名(不加HTTP)（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>siteadmin</td>\n<td>网站管理员用户名（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>siteadmin12345</td>\n<td>网站管理员密码（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td><a href=\"mailto:siteadmin@gmail.com\">siteadmin@gmail.com</a></td>\n<td>网站管理员邮箱（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>smtp.mailgun.org</td>\n<td>邮箱HOST（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>587</td>\n<td>邮箱端口。只能用587端口（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>邮箱用户名</td>\n<td>邮箱用户名（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>邮箱密码</td>\n<td>邮箱密码（或者授权码）（<strong>必改</strong>）</td>\n</tr>\n<tr>\n<td>tls</td>\n<td>邮箱协议。只能用TLS协议（<strong>必改</strong>）</td>\n</tr>\n</tbody></table>\n<p>如果需要一个支持SMTP TLS的邮箱服务可以使用<a href=\"/posts/domain-email/\">微信企业邮</a></p>\n<p>构建：</p>\n<div class=\"markdown-code\" data-language=\"bash\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 19h8\"></path><path d=\"m4 17 6-6-6-6\"></path></svg><span>bash</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-bash\">docker compose up -d</code></pre></div><p>如果遇到 <code>docker.io</code> 无法访问。可以使用镜像源</p>\n<p>部署完毕后查看 <code>discourse-discourse-1</code> 容器的日志</p>\n<p>如果看到下述日志，则Discourse正在进行预编译资源，稍等几分钟即可</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">INFO  ==&gt; Precompiling assets, this may take some time...</code></pre></div><p>如果看到下述日志，证明Discourse已经在容器内3000端口启动了</p>\n<div class=\"markdown-code\" data-language=\"bash\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 19h8\"></path><path d=\"m4 17 6-6-6-6\"></path></svg><span>bash</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-bash\">Accessible via: http://0.0.0.0:3000/</code></pre></div><p>接下来访问你设置的域名（如果没有做解析或者网站在内网可以使用Cloudflare Tunnel曲线救国）</p>\n<p>访问，大功告成</p>\n<p><img src=\"https://b.acofork.com/img/discourse-2025-05-02-22-20-51-image.webp\" alt=\"2025-05-02-22-20-51-image.webp\" width=\"1375\" height=\"929\" loading=\"eager\" decoding=\"async\" /></p>\n","toc":[{"id":"正式开始","text":"正式开始","depth":2}]}