当我从我的图像运行一个docker容器时,我尝试添加一个rabbitmq用户,但它抱怨该节点已关闭:
Error: unable to connect to node rabbit@3af546685019: nodedown
DIAGNOSTICS
===========
attempted to contact: [rabbit@3af546685019]
rabbit@3af546685019:
* connected to epmd (port 4369) on 3af546685019
* epmd reports: node 'rabbit' not running at all
no other nodes on 3af546685019
* suggestion: start the node
current node details:
- node name: 'rabbitmq-cli-55@3af546685019'
- home dir: /var/lib/rabbitmq
- cookie hash: pgr3C5mfbuw86BKnW7cJpw==
Error: unable to connect to node rabbit@3af546685019: nodedown
这是我的Dockerfile:
FROM rabbitmq:3.6.14
ADD rabbitmq_users.sh /usr/lib/rabbitmq/bin
WORKDIR /usr/lib/rabbitmq/bin
RUN rabbitmq-plugins enable --offline rabbitmq_management
ENTRYPOINT ["rabbitmq_users.sh"]
EXPOSE 4369 25672 5672 15672
和rabbitmq_users.sh:
#!/bin/sh
echo "Creating a user..."
sleep 10
rabbitmqctl add_user rmquser rmquser 2>/dev/null
rabbitmqctl set_user_tags rmquser administrator
rabbitmqctl set_permissions -p / rmquser ".*" ".*" ".*"
看起来它先从rabbitmq运行rabbitmq-server之前执行rabbitmq_users.sh:3.6.14我继承的图像因为我看不到任何证明rabbitmq服务器启动的日志。例如,如果我不创建禁用此ENTRYPOINT脚本的用户,则服务器启动并且工作正常。
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
rabbitmq image已将入口点定义为ENTRYPOINT ["docker-entrypoint.sh"]
。定义入口点时,将覆盖基本映像中定义的入口点。因此,rabbitmq不会开始。
你需要做的是"追加"您的用户脚本:
FROM rabbitmq:3.6.14
ADD rabbitmq_users.sh /usr/lib/rabbitmq/bin
WORKDIR /usr/lib/rabbitmq/bin
RUN rabbitmq-plugins enable --offline rabbitmq_management
ENTRYPOINT ["./usr/local/bin/docker-entrypoint.sh rabbitmq-server && ./rabbitmq_users.sh"]
EXPOSE 4369 25672 5672 15672
答案 1 :(得分:0)
我可以通过像这样调整我的rabbitmq_users.sh来实现它:
#!/bin/sh
# Create Rabbitmq user
(rabbitmqctl add_user rmquser rmquser 2>/dev/null ; \
rabbitmqctl set_user_tags rmquser administrator ; \
rabbitmqctl set_permissions -p / rmquser ".*" ".*" ".*" ; \
echo "User 'rmquser' has been created") & rabbitmq-server
并使用CMD而不是ENTRYPOINT,我提供了我的脚本:
...
CMD ["rabbitmq_users.sh"]