本文介绍了Docker中的RabbitMQ-用户创建未持久的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,用户 user1 不能持久保存在我使用以下Dockerfile创建的容器中。这是什么原因呢?这是RabbitMQ的特定问题吗?例如我必须明确指定必须保留用户

I've got a problem where the user user1 is not persisted in the container that I have created using the following Dockerfile. What is the reason for this? Is this a RabbitMQ specific issue? e.g. I have to explicitly specify that a user must be persisted

FROM dockerfile/rabbitmq

# Define mount points.
VOLUME ["/data/log", "/data/mnesia"]

# Define working directory.
WORKDIR /data

RUN (rabbitmq-start &) && \
  sleep 10 && \
  rabbitmqctl add_user user1 password1 && \
  rabbitmqctl set_user_tags user1 administrator && \
  rabbitmqctl set_permissions -p / user1 ".*" ".*" ".*"  && \
  sleep 10 && \
  rabbitmqctl stop && \
  sleep 10
# Define default command.
CMD ["rabbitmq-start"]

# Expose ports.
EXPOSE 5672
EXPOSE 15672


推荐答案

我知道这是一个老问题,但是今天这个问题苦了几个小时,终于为我解决了:
这个问题似乎是由于Docker在每个新容器中默认主机名都发生了变化,而RabbitMQ实际上绑定了

I know it's an old question, but struggled for hours with this problem today and finally solved it for me:The issue seems to be due to the default hostname changing at every new container with Docker, and RabbitMQ actually binds the configuration to the host name.

在设置用户之前,我在/etc/rabbitmq/rabbitmq-env.conf中设置了NODENAME变量:

I set the NODENAME variable in /etc/rabbitmq/rabbitmq-env.conf before setting up the user:

# make the node name static
RUN echo 'NODENAME=rabbit@localhost' > /etc/rabbitmq/rabbitmq-env.conf

现在可以使用了。

希望它能提供帮助。

编辑:

这是一个有效的 Dockerfile (将rabbitmq-env.conf文件复制到容器中):

Here is a working Dockerfile (copying a rabbitmq-env.conf file to the container):

FROM ubuntu:latest

RUN groupadd -r rabbitmq && useradd -r -d /var/lib/rabbitmq -m -g rabbitmq rabbitmq

# add rabbitmq repo
RUN apt-get update && \
apt-get install wget --assume-yes && \
wget https://www.rabbitmq.com/rabbitmq-signing-key-public.asc && \
sudo apt-key add rabbitmq-signing-key-public.asc && \
sed -i -e '1ideb http://www.rabbitmq.com/debian/ testing main\' /etc/apt/sources.list && \
apt-get update && \
apt-get install rabbitmq-server --assume-yes

# Enable plugins
RUN rabbitmq-plugins enable rabbitmq_management && \
rabbitmq-plugins enable rabbitmq_web_stomp && \
rabbitmq-plugins enable rabbitmq_mqtt

# expose ports
# Management
EXPOSE  15672
# Web-STOMP plugin
EXPOSE  15674
# MQTT:
EXPOSE  1883


# configure RabbitMQ
COPY ["rabbitmq-env.conf", "/etc/rabbitmq/rabbitmq-env.conf"]
RUN chmod 755 /etc/rabbitmq/rabbitmq-env.conf

# Create users for the apps
COPY ["rabbitmq-setup.sh", "/tmp/rabbitmq/rabbitmq-setup.sh"]
RUN mkdir /var/run/rabbitmq && \
chmod -R 755 /var/run/rabbitmq && \
chown -R rabbitmq:rabbitmq /var/run/rabbitmq && \
service rabbitmq-server start && \
sh /tmp/rabbitmq/rabbitmq-setup.sh && \
rm /tmp/rabbitmq/rabbitmq-setup.sh && \
service rabbitmq-server stop

# start rabbitmq
USER rabbitmq
CMD ["rabbitmq-server", "start"]

我的 rabbitmq-env.conf 文件:

NODENAME=rabbimq@localhost

我的 rabbitmq-setup.sh

rabbitmqctl add_vhost myvhost && rabbitmqctl add_user myuser mypasswd && rabbitmqctl set_permissions -p myvhost myuser ".*" ".*" ".*" && rabbitmqctl set_user_tags myuser administrator

这篇关于Docker中的RabbitMQ-用户创建未持久的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:11