# 如何减小 discourse Docker 镜像大小？

**URL:** <https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249>\
**Category:** Self-hosting\
**Created:** [2025 年8 月 12 日 06:19 UTC](https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249 "2025-08-12T06:19:16Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

作者： ![harishg33](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/harishg33/32/496490_2.png) [@harishg33](https://meta.discourse.org/u/harishg33)\
发布日期： [2025 年8 月 12 日 11:40 UTC](https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249/4 "2025-08-12T11:40:26Z")

</div>

我尝试用精简版基础镜像替换普通基础镜像，然后它就开始失败了。我看到了很多不同类型的错误，所以我不知道是什么原因导致的。

> **错误集 1**
>
> /usr/local/lib/ruby/gems/3.3.0/gems/bundler-2.6.4/lib/bundler/definition.rb:683:in `materialize’: Could not find bootsnap-1.18.6, actionmailer-8.0.2, actionpack-8.0.2, actionview-8.0.2, activemodel-8.0.2, activerecord-8.0.2, activesupport-8.0.2, railties-8.0.2, propshaft-1.2.1, json-2.13.0, actionview\_precompiler-0.4.0, discourse-seed-fu-2.3.12, mail-2.8.1, mini\_mime-1.1.5, mini\_suffix-0.3.3, redis-5.4.0, redis-namespace-1.11.0, active\_model\_serializers-0.8.4, http\_accept\_language-2.1.1, discourse-fonts-0.0.19, discourse-emojis-1.0.41, message\_bus-4.4.1, rails\_multisite-7.0.0, fastimage-2.3.1, aws-sdk-s3-1.182.0, aws-sdk-sns-1.96.0, excon-1.2.5, unf-0.2.0, email\_reply\_trimmer-0.2.0, image\_optim-0.31.4, multi\_json-1.17.0, mustache-1.1.1, nokogiri-1.18.8-x86\_64-linux-gnu, loofah-2.24.1, css\_parser-1.21.1, omniauth-2.1.2, omniauth-facebook-9.0.0, omniauth-twitter-1.4.0, omniauth-github-2.0.0, omniauth-oauth2-1.7.3, omniauth-google-oauth2-1.0.1, oj-3.16.11, pg-1.5.9, mini\_sql-1.6.0, pry-rails-0.3.11, pry-byebug-3.11.0, rtlcss-0.2.1, messageformat-wrapper-1.1.0, rake-13.3.0, thor-1.4.0, diffy-3.4.4, rinku-2.0.6, sidekiq-7.3.9, mini\_scheduler-0.18.0, execjs-2.10.0, mini\_racer-0.19.0, highline-3.1.2, rack-2.2.17, rack-protection-3.2.0, cbor-0.5.9.8, cose-1.3.1, addressable-2.8.7, json\_schemer-2.4.0, net-imap-0.5.9, digest-3.2.0, capybara-3.40.0, webmock-3.25.1, simplecov-0.22.0, test-prof-1.4.4, rails-dom-testing-2.3.0, minio\_runner-1.0.0, capybara-playwright-driver-0.5.6, rspec-3.13.1, listen-3.9.0, certified-1.0.0, fabrication-3.0.0, mocha-2.7.1, rb-fsevent-0.11.2, rspec-rails-8.0.1, shoulda-matchers-6.5.0, rspec-html-matchers-0.10.0, pry-stack\_explorer-0.6.1, byebug-12.0.0, rubocop-discourse-3.12.1, parallel\_tests-5.3.0, rswag-specs-2.16.0, annotaterb-4.17.0, syntax\_tree-6.3.0, rspec-multi-mock-0.3.1, ruby-prof-1.7.2, bullet-8.0.8, better\_errors-2.10.1, binding\_of\_caller-1.0.1, yaml-lint-0.1.2, yard-0.9.37, discourse\_dev\_assets-0.0.5, faker-3.5.2, fast\_blank-1.0.1, lru\_redux-1.1.0, htmlentities-4.3.4, rack-mini-profiler-4.0.0, unicorn-6.1.0, puma-6.6.0, rbtrace-0.5.2, ruby-readability-0.7.2, stackprof-0.2.27, memory\_profiler-1.1.0, cppjieba\_rb-0.4.4, lograge-0.14.0, logstash-event-1.2.02, logster-2.20.1, sassc-embedded-1.80.2, rotp-6.3.0, rqrcode-3.1.0, rubyzip-2.4.1, sshkey-3.0.0, rchardet-1.9.0, lz4-ruby-0.3.3, sanitize-7.0.0, web-push-3.0.1, colored2-4.0.3, maxminddb-0.1.22, rails\_failover-2.3.0, faraday-2.13.3, faraday-retry-2.3.2, net-http-0.6.0, cgi-0.5.0, tzinfo-data-1.2025.2, csv-3.3.5, iso8601-0.13.0, rrule-0.6.0, dry-initializer-3.2.0, parallel-1.27.0, inflection-1.0.0, multipart-post-2.4.1, faraday-multipart-1.1.1, zendesk\_api-1.38.0.rc1, stripe-11.1.0, sawyer-0.9.2, octokit-5.6.1, tokenizers-0.5.5-x86\_64-linux, tokenizers-0.5.5, tiktoken\_ruby-0.0.11.1-x86\_64-linux, discourse\_ai-tokenizers-0.3.1, ed25519-1.4.0, Ascii85-2.0.1, ruby-rc4-0.1.5, hashery-2.1.2, ttfunk-1.8.0, afm-0.2.2, pdf-reader-2.14.1, msgpack-1.8.0, activejob-8.0.2, rack-session-1.0.2, rack-test-2.2.0, rails-html-sanitizer-1.6.2, useragent-0.16.11, builder-3.3.0, erubi-1.13.1, timeout-0.4.3, base64-0.3.0, benchmark-0.4.1, bigdecimal-3.2.2, concurrent-ruby-1.3.5, connection\_pool-2.5.3, drb-2.2.3, i18n-1.14.7, logger-1.7.0, minitest-5.25.5, securerandom-0.4.1, tzinfo-2.0.6, uri-1.0.3, irb-1.15.2, rackup-1.0.1, zeitwerk-2.7.3, ffi-1.17.2-x86\_64-linux-gnu, redis-client-0.25.1, aws-sdk-core-3.226.0, aws-sdk-kms-1.99.0, aws-sigv4-1.12.1, exifr-1.4.1, fspath-3.1.2, image\_size-3.4.0, in\_threads-1.6.0, progress-3.6.0, racc-1.8.1, crass-1.0.6, hashie-5.0.0, omniauth-oauth-1.2.1, oauth2-1.4.11, jwt-2.10.1, ostruct-0.6.3, pry-0.15.2, libv8-node-24.1.0.0-x86\_64-linux, libv8-node-24.1.0.0, reline-0.6.2, openssl-signature\_algorithm-1.3.0, public\_suffix-6.0.2, hana-1.3.7, regexp\_parser-2.10.0, simpleidn-0.2.3, date-3.4.1, matrix-0.4.3, xpath-3.2.0, crack-1.0.0, hashdiff-1.2.0, docile-1.4.1, simplecov-html-0.13.2, simplecov\_json\_formatter-0.1.4, playwright-ruby-client-1.52.0, rspec-core-3.13.5, rspec-expectations-3.13.5, rspec-mocks-3.13.5, rb-inotify-0.11.1, rspec-support-3.13.4, lint\_roller-1.1.0, rubocop-1.78.0, rubocop-capybara-2.22.1, rubocop-factory\_bot-2.27.1, rubocop-rails-2.32.0, rubocop-rspec-3.6.0, rubocop-rspec\_rails-2.31.0, json-schema-5.2.1, prettier\_print-1.2.1, uniform\_notifier-1.17.0, rouge-4.6.0, debug\_inspector-1.2.0, literate\_randomizer-0.4.0, kgio-2.11.4, raindrops-0.20.1, nio4r-2.7.4, optimist-3.2.1, guess\_html\_encoding-0.0.11, rexml-3.4.1, request\_store-1.7.0, sass-embedded-1.85.0-x86\_64-linux-gnu, chunky\_png-1.4.0, rqrcode\_core-2.0.0, openssl-3.3.0, faraday-net\_http-3.4.1, globalid-1.2.1, pp-0.6.2, rdoc-6.14.2, webrick-1.9.1, aws-eventstream-1.4.0, aws-partitions-1.1117.0, jmespath-1.6.2, oauth-1.1.0, multi\_xml-0.7.2, coderay-1.1.3, method\_source-1.1.0, io-console-0.8.1, mime-types-3.7.0, diff-lcs-1.6.2, language\_server-protocol-3.17.0.5, parser-3.3.8.0, rainbow-3.1.1, rubocop-ast-1.46.0, ruby-progressbar-1.13.0, unicode-display\_width-3.1.4, google-protobuf-4.31.1-x86\_64-linux-gnu, google-protobuf-4.31.1, erb-5.0.2, psych-5.2.6, oauth-tty-1.0.5, snaky\_hash-2.0.3, version\_gem-1.1.8, mime-types-data-3.2025.0715, ast-2.4.3, prism-1.4.0, unicode-emoji-4.0.4, stringio-3.1.7 in locally installed gems (Bundler::GemNotFound)

和

`supervisor pid: 577 unicorn pid: 583`  
`./config/unicorn_launcher: line 66: unicorn: command not found`

编辑：抱歉打扰了。这些失败可能只是因为构建时失败。不知何故，构建看起来完成了，但现在我看到一些步骤失败了。特别是 `cd /var/www/discourse &amp;&amp; su discourse -c 'bundle install --jobs $(($(nproc) - 1)) --retry 3'`，由于权限问题。不过我想知道，为什么这在精简版和普通版基础镜像之间会有变化？

> **构建步骤中的错误**
>
> `Retrying download gem from `[`https://rubygems.org/`](https://rubygems.org/)`due to error (2/4): Bundler::PermissionError There was an error while trying to write to `/usr/local/lib/ruby/gems/3.3.0/cache/rake-13.3.0.gem`. It is likely that you need to grant write permissions for that path.`

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249)._
