【问题标题】:Execute script after docker builddocker build 后执行脚本
【发布时间】:2020-12-29 12:17:24
【问题描述】:

我正在使用 docker 构建一个 RabbitMQ 代理,并在我的 Dockerfile 中使用了官方 docker 映像 (rabbitmq:3)。

我需要启动一个脚本 (setup.sh) 来为代理设置用户和管理员。

当我执行 Dockerfile 时,

FROM rabbitmq:3
COPY provision /usr/src/provision
WORKDIR /usr/src/provision
EXPOSE 15672
EXPOSE 5672
EXPOSE 4369
RUN ./setup.sh

我明白了:

Error: unable to perform an operation on node 'rabbit@db52ce2c88d9'. Please see diagnostics information and suggestions below.

Most common reasons for this are:

 * Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
 * CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
 * Target node is not running

In addition to the diagnostics info below:

 * See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
 * Consult server logs on node rabbit@db52ce2c88d9
 * If target node is configured to use long node names, don't forget to use --longnames with CLI tools

DIAGNOSTICS
===========

attempted to contact: [rabbit@db52ce2c88d9]

rabbit@db52ce2c88d9:
  * connected to epmd (port 4369) on db52ce2c88d9
  * epmd reports: node 'rabbit' not running at all
                  no other nodes on db52ce2c88d9
  * suggestion: start the node

Current node details:
 * node name: 'rabbitmqcli-4810-rabbit@db52ce2c88d9'
 * effective user's home directory: /var/lib/rabbitmq
 * Erlang cookie hash: tql1bCPiwbtLGtuDAB3tOQ==
---------------------------------------------------------------------------
Removing intermediate container db52ce2c88d9
 ---> 79851f024ae3
Successfully built 79851f024ae3
Successfully tagged rmq_v0:latest

如何在删除中间容器后执行文件,但也不是docker exec 命令,它必须自动化。

谢谢:)

【问题讨论】:

    标签: docker rabbitmq dockerfile


    【解决方案1】:

    您正在尝试向服务发送命令,而在此之前没有启动它。我建议不要将数据添加到图像本身,而是在它启动之后。根据这些镜像的执行位置(普通 Docker、Docker Swarm、Kubernetes 等),您可以在预热过程中添加初始数据(在 init 之前)。根据此操作所花费的时间和扩展需求(以及此数据的可变性以及将执行所有这些操作的基础设施),可以对此步骤进行一些性能改进,例如,使用在启动新实例之前已经应用了二进制数据。

    【讨论】:

    • @Camille SAURY 如果这个答案没有帮助,请评论原因。
    猜你喜欢
    • 1970-01-01
    • 2019-06-23
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多