docker 构建后执行脚本
Execute script after docker build
我正在使用 docker 构建一个 RabbitMQ 代理并使用官方 docker 图像(rabbitmq: 3) 在我的 Dockerfile 中。
我需要启动脚本 (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、Docker Swarm、Kubernetes 等),您可以在预热过程中(在初始化之前)添加初始数据。根据此操作所花费的时间和扩展需求(以及此数据的可变性和将执行所有这些操作的基础设施),可以对此步骤进行一些性能改进,例如,克隆一个卷在启动新实例之前已应用二进制数据。
我正在使用 docker 构建一个 RabbitMQ 代理并使用官方 docker 图像(rabbitmq: 3) 在我的 Dockerfile 中。
我需要启动脚本 (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、Docker Swarm、Kubernetes 等),您可以在预热过程中(在初始化之前)添加初始数据。根据此操作所花费的时间和扩展需求(以及此数据的可变性和将执行所有这些操作的基础设施),可以对此步骤进行一些性能改进,例如,克隆一个卷在启动新实例之前已应用二进制数据。