'Docker rabbitmq doesn't work with RABBITMQ_DEFAULT_USER and RABBITMQ_DEFAULT_PASS
I'm trying to run rabbitmq service with following configuration:
version: '3.9'
services:
rabbit-mq:
container_name: rabbitmq
image: rabbitmq:3-management
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
RABBITMQ_DEFAULT_VHOST: 'test'
ports:
- '5672:5672'
- '15672:15672'
networks:
monorepo:
gateway:
container_name: gateway
environment:
- APP_PORT=${GATEWAY_MS_PORT}
build:
context: .
args:
- APP_NAME=monorepo-project
ports:
- ${GATEWAY_MS_PORT}:${GATEWAY_MS_PORT}
networks:
monorepo:
user-microservice:
container_name: user-microservice
environment:
- APP_PORT=${USER_MS_PORT}
build:
context: .
args:
- APP_NAME=user-microservice
ports:
- ${USER_MS_PORT}:${USER_MS_PORT}
networks:
monorepo:
depends_on:
- user-microservice-db
user-microservice-db:
image: mysql:latest
container_name: user-microservice-db
environment:
MYSQL_ROOT_PASSWORD: ${USER_MS_MYSQL_PASSWORD}
MYSQL_DATABASE: ${USER_MS_MYSQL_DATABASE}
ports:
- ${USER_MS_MYSQL_PORT}:${INTERNAL_DB_PORT}
networks:
monorepo:
networks:
monorepo:
However, rabbitmq service give me the following error:
2022-04-03 12:59:28.937375+00:00 [info] <0.1164.0> closing AMQP connection <0.1164.0> (172.31.0.5:37026 -> 172.31.0.3:5672)
2022-04-03 12:59:30.941567+00:00 [info] <0.1171.0> accepting AMQP connection <0.1171.0> (172.31.0.5:37028 -> 172.31.0.3:5672)
2022-04-03 12:59:30.947123+00:00 [error] <0.1171.0> Error on AMQP connection <0.1171.0> (172.31.0.5:37028 -> 172.31.0.3:5672, state: starting):
2022-04-03 12:59:30.947123+00:00 [error] <0.1171.0> PLAIN login refused: user 'guest' - invalid credentials
Without default user and pass it works as expected. I've been searching for resolve last couple of days and have tried all suggestions from google.
Also, with my RABBITMQ_DEFAULT_USER
and RABBITMQ_DEFAULT_PASS
I can login into managment plugin without any problem.
My .env file:
#RABBITMQ CONFIG
RABBITMQ_DEFAULT_USER=monorepo
RABBITMQ_DEFAULT_PASS=monorepo
RABBITMQ_PORT=5672
RABBITMQ_URL=rabbitmq
RABBITMQ_QUEUE=users
Solution 1:[1]
After 3.8 the environment variables that you are using are no longer supported.
WARNING: As of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used. Please use a configuration file instead; visit rabbitmq.com/configure to learn more about the configuration file. For a starting point, the 3.8 images will print out the config file it generated from supplied environment variables.
Use something like this in /etc/rabbitmq/definitions.json
:
{
"rabbit_version": "3.9",
{
"name": "test12",
"password_hash": "kI3GCqW5JLMJa4iX1lo7X4D6XbYqlLgxIs30+P6tENUV2POR,
"hashing_algorithm": "rabbit_password_hashing_sha256",
"tags": "administrator"
}
],
"vhosts": [
{
"name": "\/"
},
],
"permissions": [
{
"user": "local_jobs",
"vhost": "\/",
"configure": ".*",
"write": ".*",
"read": ".*"
}
],
"parameters": [],
"policies": [],
"queues": [],
"exchanges": [],
"bindings": []
}
Then add ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json:ro
to your volumes in your docker-compose.yaml.
The username and password is test12
.
Solution 2:[2]
I don't know why, but default_pass
doesn't appear in /etc/rabbitmq.conf.
Solution for me was:
- delete environments
mkdir ./rabbit_config
touch ./rabbit_config/rabbitmq.conf
- put in
./rabbit_config/rabbitmq.conf
:
default_user = username
default_pass = password
- add to docker-compose.yml:
volumes:
- ./rabbit_config/rabbitmq.conf:/etc/rabbitmq/conf.d/advanced.conf
docker-compose down
&docker-compose up -d
And username
, password
became valid credentinals.
P.S. On top of that, environment has just started work with no reason
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | yomateo |
Solution 2 | ????? ??????? |