# Docker 安装有什么优势吗？

**URL:** <https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128>\
**Category:** Self-hosting\
**Tags:** unsupported-install\
**Created:** [2023年四月10日 00:00 UTC](https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128 "2023-04-10T00:00:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagath](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jagath](https://meta.discourse.org/u/jagath)\
**Post date:** [2023年四月10日 00:00 UTC](https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128/1 "2023-04-10T00:00:21Z")

</div>

我知道这里的文档和许多帖子都建议 Docker 是唯一（好的）前进方向，但我想知道其中的原因。我有一个每月 3.50 美元的 Amazon Lightsail Debian 服务器，并在 20 分钟内运行了 Discourse。我使用 rbenv 安装了 Ruby 3.2.2，其余都很简单。我发现 Discourse 也不遵循 Rails 约定，例如为什么有一个 `./config/discourse.conf` 和 `GlobalSetting` 而不是 `config/environments/production.rb` 来指定这些值——这是否就是 Docker 镜像最终创建的内容（还有 `sidekiq.yml` 没有生产环境值）。

在 Docker 上运行它有什么优势吗？我想知道我是否错过了什么……

---

<div class="post-metadata">

**Author:** ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)\
**Post date:** [2023年四月10日 00:06 UTC](https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128/2 "2023-04-10T00:06:12Z")

</div>

简而言之，如果您没有使用标准安装，我们就无法在此为您提供任何帮助。如果偏离该路径，可能会出现太多问题。

---

<div class="post-metadata">

**Author:** ![jagath](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jagath](https://meta.discourse.org/u/jagath)\
**Post date:** [2023年四月10日 00:40 UTC](https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128/3 "2023-04-10T00:40:10Z")

</div>

明白了，是的，不同的操作系统等等。已经有人问我怎么做到的了——我在这里发帖以防万一。

需要 Ruby 3.2.x（通过 `rbenv`，这样你就不会受制于操作系统）、Node v16.19.x/npm 8.19.x 和 PostgreSQL（可能任何高于 11 的版本）。

1. 我创建了一个 `.ruby-version` 文件，其中指定了我安装的 Ruby 版本（`3.2.2`）。
2. 运行 `bundle`，所有 gem 都构建成功。
3. 在 PostgreSQL 本身中，我必须设置数据库：

```plaintext
CREATE DATABASE discourse;
CREATE USER discourse WITH password 'fA....';
GRANT ALL PRIVILEGES ON DATABASE discourse TO discourse;
\c discourse
GRANT ALL ON SCHEMA public TO discourse;

```

我惊讶地发现 `database.yml` 不接受 `production` 变量（这似乎非常不符合 Rails 的约定）。所有数据库设置都在 `config/discourse.conf` 中，以及 SMTP 值。我填入了这些信息。

然后运行数据库迁移：

```plaintext
bundle exec rails db:migrate

```

一切正常，迁移成功。

1. 在 `config/sidekiq.yml` 中，在 `development` 部分之后，我添加了：

```plaintext
production:
  :concurrency: 2
  :queues:
    - [critical, 2]
    - [default, 1]
    - [low]
    - [ultra_low]

```

1. 然后编辑 `lib/tasks/assets.rake`，大约在第 151 行，添加：

```plaintext
harmony: true,

```

使其看起来像：

```plaintext
  uglified, map =
    Uglifier.new(
      comments: :none,
      harmony: true,
      source_map: {
        filename: File.basename(from),
        output_filename: File.basename(to),
      },
    ).comp

```

并安装以下 npm 包：

```plaintext
npm install terser
npm install -g uglify-js@"<3"

```

然后构建资源：

```plaintext
RAILS_ENV=production bundle exec rake assets:precompile

```

然后就成功了！现在这应该可以工作了：

```plaintext
 bundle exec sidekiq -e production -C config/sidekiq.yml
 bundle exec puma --config config/puma.rb -e production

```

这使得 `sidekiq` 和 `puma` Web 服务器运行起来。

（便宜得多，而且控制更多，例如，我已经在使用 Ruby 3.2.2 了）。大部分时间都在处理那些怪癖（比如寻找 `production` 值，因为它们不在应该在的地方）。但除此之外，还是相当快的！

---

<div class="post-metadata">

**Author:** ![Heliosurge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/heliosurge/32/571810_2.png) [@Heliosurge](https://meta.discourse.org/u/Heliosurge)\
**Post date:** [2023年四月11日 22:52 UTC](https://meta.discourse.org/t/is-there-an-advantage-to-a-docker-installation/261128/4 "2023-04-11T22:52:26Z")

</div>

这相当令人印象深刻。但正如前面提到的，如果遇到导致网站崩溃的问题，那么您可能会被限制在非常有限的社区中寻求帮助。因此，最大的风险/缺点是潜在的长时间甚至灾难性的停机，这可能需要完全重新安装。

网站停机时间越长，您的网站声誉和会员可能会遭受的损失就越大。

如果您只是在尝试，并且不真正依赖稳定的生产网站。那么您冒的风险并不大，只是浪费时间。
