如何修改 Dockerfile?

我还有其他几个 Docker 容器,我像这样运行步骤:

# 将当前目录的内容复制到容器的 /app 目录
COPY html /usr/share/nginx/html/
COPY dim.local.crt /etc/nginx/ssl/
COPY dim.local.key /etc/nginx/ssl/
COPY nginx.conf /etc/nginx/
COPY default.conf /etc/nginx/sites-enabled/

# 安装 requirements.txt 中指定的任何所需包
#RUN pip install -r requirements.txt

# COPY 命令后需要重启 nginx 吗?
RUN 

RUN apt-get update \
    && apt-get install -y nano \
    && rm -fr /var/lib/apt/lists/*

我需要对我的 Discourse 容器执行一些类似的步骤,但 Dockerfile 在哪里?我读到也许可以将这些添加到 containers/app.yml 的末尾,但我不太确定。

有人能解释一下吗?

你能具体说明一下你需要什么吗?

无需修改 Docker 文件来添加自定义证书,我们有一份相关指南:Allow SSL / HTTPS for your Discourse Docker setup

我不想完全照搬。我只是想把一些 shell 脚本和 crontab 复制到容器中,以便自动化某些任务。

app.yml 的最后 5 行包含运行自定义命令的示例,例如添加

- exec: curl example.com/script.sh | bash

这将下载并执行该脚本。

是的,我看到了,但每次我重新构建时都会出现复制错误:

## 构建后要运行的任何自定义命令
run:
  - exec: echo "开始执行自定义命令"
  ## 如果你想为首次注册设置'发件人'电子邮件地址,请取消注释并修改:
  ## 收到第一封注册邮件后,请重新注释该行。它只需要运行一次。
  #- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
  
  - exec: cp /shared/rr/run_badges.sh /etc/cron.d/.
  - exec: cp /shared/rr/badges /etc/cron.d/.
  - exec: echo "自定义命令执行完毕"

也请分享错误日志。

我确实可以从 URL 拉取它们,这倒是个想法。

文件确实存在于主机上:

# ls -al shared/rr/
badges         run_badges.sh
#

这是错误信息:

FAILED
--------------------
Pups::ExecError: cp /shared/rr/run_badges.sh /etc/cron.d/. failed with return #<Process::Status: pid 1457 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params "cp /shared/rr/run_badges.sh /etc/cron.d/."
e23ff12630c8058c4b36ee8673404dafbe6791ec61aa630f1224400eba4e75e0
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.

容器内的 /shared 目录默认映射到 /var/discourse/shared/standalone,因此该路径下缺少一个目录。

我哪里做错了 @Falco

命令:

- exec: cp /shared/standalone/sql/run_badges.sh /root
Pups::ExecError: cp /shared/standalone/sql/run_badges.sh /root 失败,返回 #<Process::Status: pid 1728 exit 1>

实际上,这个解决方案运行得相当不错。感谢你的分享。