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

**URL:** <https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249>\
**Category:** Self-hosting\
**Created:** [2025年八月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:** 1

<div class="post-metadata">

**Author:** ![harishg33](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/harishg33/32/496490_2.png) [@harishg33](https://meta.discourse.org/u/harishg33)\
**Post date:** [2025年八月12日 06:19 UTC](https://meta.discourse.org/t/how-can-i-minimize-the-discourse-docker-image-size/378249/1 "2025-08-12T06:19:16Z")

</div>

大家好：

我们在 K8s 集群中部署 Discourse，需要构建一个镜像，但该集群有一些限制，例如无法访问外部互联网等。该论坛是内部使用的，所以这方面没有问题。为了实现这一点，我遵循了官方支持的安装方法，并基于启动脚本的 bootstrap 和 run 命令创建了一个 Dockerfile，其中我们执行了所有不需要数据库的构建时步骤，以及在启动时执行的其余步骤。启动速度有点慢，但目前还可以接受。

这样做的一个问题是最终镜像相当大（约 2GB），因为我使用 Discourse 基础镜像来运行启动脚本。我查看了基础镜像的 Dockerfile - [https://github.com/discourse/discourse\_docker/blob/master/image/base/Dockerfile。看起来安装了很多东西，比如](https://github.com/discourse/discourse_docker/blob/master/image/base/Dockerfile%E3%80%82%E7%9C%8B%E8%B5%B7%E6%9D%A5%E5%AE%89%E8%A3%85%E4%BA%86%E5%BE%88%E5%A4%9A%E4%B8%9C%E8%A5%BF%EF%BC%8C%E6%AF%94%E5%A6%82) postgres 和 redis。我们正在尝试使用多容器方法，其中 discourse、redis 和 postgres 在不同的容器中。我明白这是一个通用的基础镜像，适用于所有支持的安装方式。但我正在寻找一种方法来减小最终镜像的大小。此外，移除不必要的东西在漏洞方面会更好。

我的问题是，我是否可以安全地移除基础 Docker 镜像中安装的 postgres、redis 依赖项，而不会破坏 Discourse 应用程序的任何功能？另外，是否可以从最终镜像中移除 curl、wget 等工具，因为在我们的设置中它们很少需要，而且控制台几乎无法访问。

---

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