Skip to content

Setting RABBITMQ_NODE_PORT doesn't seem to effect #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aomerk opened this issue Apr 18, 2021 · 7 comments · Fixed by #487
Closed

Setting RABBITMQ_NODE_PORT doesn't seem to effect #480

aomerk opened this issue Apr 18, 2021 · 7 comments · Fixed by #487
Labels

Comments

@aomerk
Copy link

aomerk commented Apr 18, 2021

What do I want to achieve?

Make rabbitmq listen for amqp connections on a port other than default 5672

My constraints

I do not want to use a config file, I want to achieve this via environment variables

What did I try?

Same results when I try:

  • In my development environment, I use docker-compose with rabbitmq:alpine image (13b87dec7346643343e297673c9ac6b80b68ddb8af70b3b34a55a8a4209ca2d2)

  • single docker container, with alpine image:
    docker run -it --rm -e RABBITMQ_NODE_PORT=8989 rabbitmq:alpine

  • single docker container, with rabbitmq image (f83a0c22b15ab5f71a8fe2c2ff5366a78e967bf27298df181f161de04e4d8c9a)
    docker run -it --rm -e RABBITMQ_NODE_PORT=8989 rabbitmq

Which versions did I use?

I tried it on two different machines.
Docker version 20.10.5, build 55c4c88 on Linux ubuntu 5.8.0-45-generic #51~20.04.1-Ubuntu SMP Tue Feb 23 13:46:31 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

and

Docker version 20.10.6, build 370c28948e
on Linux 5.11.15-arch1-2 #1 SMP PREEMPT Sat, 17 Apr 2021 00:22:30 +0000 x86_64 GNU/Linux

What did I want to see?

Rabbitmq to use my port

...
2021-04-18 14:14:24.828 [info] <0.875.0> started TCP listener on [::]:8989
...

What do I see?

...
2021-04-18 14:14:24.828 [info] <0.875.0> started TCP listener on [::]:5672
...
@wglambert
Copy link

Because the entrypoint sets listeners.tcp.default it seems to take precedence over the environment variable

See also #449 and #251 (comment)

the RABBITMQ_NODE_PORT comes from variables supported by rabbitmq server directly: https://www.rabbitmq.com/configure.html#define-environment-variables; it is not something that is specific to the Docker image

Supplying a config file works fine

$ cat rabbitmq.conf 
loopback_users.guest = false
listeners.tcp.default = 8989
management.tcp.port = 18989

$ docker run -d --name rabbit -v "$PWD"/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf rabbitmq:management
9d118692f50d8c374f22b38ea5a4fb4495bd97f69efc4b184fbfe729617377fb

$ docker logs rabbit 2>&1 | grep 8989
2021-04-19 16:10:41.365 [info] <0.794.0> Management plugin: HTTP (non-TLS) listener started on port 18989
2021-04-19 16:10:41.474 [info] <0.1032.0> started TCP listener on [::]:8989

I tried using RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS but was running into some errors:
application_controller: syntax error before: '.': listeners.tcp.default
You've tried to set listeners.tcp.default, but there is no setting with that name.
Conf file attempted to set unknown variable: loopback_users.guest

So config file it is

@aomerk
Copy link
Author

aomerk commented Apr 19, 2021

I have the same diagnosis but I have a dynamic use case where I deploy the image and then let it be configured on the fly. I can create and mount a config file on the fly but it is an unnecessary hassle.

So, I decided to use bitnami's rabbitmq image until this settles.

@yosifkit
Copy link
Member

Hey @michaelklishin, I'm a little confused. This used to work in on Apr 20, 2018; which looks like it was 3.7.4 (commit 1a37166 here). Even though the entrypoint writes a config file with listeners.tcp.default=5671, the environment variable takes precedence over the config file. But in the current image (3.8.14) it seems like the config file take precedence.

$ docker run -it --rm -e RABBITMQ_NODE_PORT=6666 rabbitmq
...
2021-04-21 18:46:37.436 [info] <0.891.0> started TCP listener on [::]:5672

After some digging, it looks like the environment variable overrides the config file all the way until 3.8.3 but not 3.8.4 and beyond. If I skip the entrypoint so that a config file is not generated, then the environment variable applies.

$ docker run -it --rm -e RABBITMQ_NODE_PORT=6666 --entrypoint rabbitmq-server --user rabbitmq rabbitmq:3.8.14

@michaelklishin
Copy link
Collaborator

@yosifkit starting with 3.8.4 configuration generation and environment variable handling have dramatically changed internally. There was a series of PRs you can see referenced in rabbitmq/rabbitmq-server#2180.

You know my take on environment variables: they are terrible. No reason to use them when there's a rabbitmq.conf option.

@michaelklishin
Copy link
Collaborator

michaelklishin commented May 12, 2021

I should also mention that "regular" users of RabbitMQ effectively never use both listener settings and RABBITMQ_NODE_PORT, or somehow we never see this on the core team.

This is fairly unique to Docker users and this image in particular. So we have to choose one or the other, and the general
direction suggested by the RabbitMQ core team has been: "make it easy to use a custom config file, drop the env variable addiction" for a good year now.

@tianon
Copy link
Member

tianon commented May 19, 2021

Ok, fair enough. Given that we currently generate the configuration that's overriding this, what do you think about this patch as a band-aid that hopefully won't live into the next release (if we can resolve #424? 🙏 three little questions in #424 (comment) 😇):

diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh
index da789b9..c1ae587 100755
--- a/docker-entrypoint.sh
+++ b/docker-entrypoint.sh
@@ -365,10 +365,10 @@ if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
 	fi
 
 	if [ "$haveSslConfig" ]; then
-		rabbit_set_config 'listeners.ssl.default' 5671
+		rabbit_set_config 'listeners.ssl.default' "${RABBITMQ_NODE_PORT:-5671}"
 		rabbit_env_config 'ssl' "${sslConfigKeys[@]}"
 	else
-		rabbit_set_config 'listeners.tcp.default' 5672
+		rabbit_set_config 'listeners.tcp.default' "${RABBITMQ_NODE_PORT:-5672}"
 	fi
 
 	rabbit_env_config '' "${rabbitConfigKeys[@]}"

if [ "$haveSslConfig" ]; then
rabbit_set_config 'listeners.ssl.default' 5671
rabbit_env_config 'ssl' "${sslConfigKeys[@]}"
else
rabbit_set_config 'listeners.tcp.default' 5672
fi

@michaelklishin
Copy link
Collaborator

@tianon that looks like a reasonable solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants