所以我对 docker-compose 和rabbitmq 有疑问。
我运行 docker-compose up。一切都开始旋转。 Docker-compose:
services:
rabbitmq3:
image: "rabbitmq:3-management"
hostname: "localhost"
command: rabbitmq-server
ports:
- 5672:5672
- 15672:15672
然后我执行
sudo rabbitmqctl status
检查与节点的连接。我收到此错误:
Error: unable to perform an operation on node 'rabbit@localhost'. 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@localhost
* If target node is configured to use long node names, don't forget to use --longnames with CLI tools
DIAGNOSTICS
===========
attempted to contact: [rabbit@localhost]
rabbit@localhost:
* connected to epmd (port 4369) on localhost
* epmd reports: node 'rabbit' not running at all
no other nodes on localhost
* suggestion: start the node
Current node details:
* node name: 'rabbitmqcli-25456-rabbit@localhost'
* effective user's home directory: /Users/olof.grund
* Erlang cookie hash: d1oONiVA/qogGxkf6vs9Rw==
当我在容器中执行此操作时
docker-compose exec -T rabbitmq3 rabbitmqctl status
它起作用了。
我需要以某种方式从 docker 公开一些东西吗?也许是一些rabbitmq客户端或节点?
我使用了在其他来源中找到的所有技巧。 (将 IP 添加到 /etc/hosts/,重新启动容器、服务)。我花了一天时间才终于让它发挥作用,归根结底就是这样。
<wait for 60secs since the rabbit container has been started>
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl force_boot
rabbitmqctl start_app
由于 Docker 执行命令是即时的,特别是在 docker build 命令中,这些命令是分离的并且不等待,有时执行
rabbitmqctl
命令会失败,因为你没有等待几秒钟。考虑放置 sleep 15
,然后执行命令。
Rabbitmq 使用 Erlang 的分发协议,需要为 EPMD(Erlang 端口映射器守护进程)打开端口 4369,在 docker-compose 中公开它并停止在主机中运行的 EPMD。