dockerrabbitmqrabbitmq-management

In rabbitMQ management console, under connection section, what does the ip and port mean in connection name?


I have this rabbitMQ docker container running:

version: '3'
services:
  rabbitmq:
    image: rabbitmq:3-management-alpine
    environment:
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest
    ports:
        - 5672:5672
        - 15672:15672
    volumes:
        - ./.rabbitmq/data/:/var/lib/rabbitmq
        - ./.rabbitmq/log/:/var/log/rabbitmq

and it runs well.

I have a nodejs script put_message_into_queue.ts, that connects to it and tries to put some message into a queue.

I also have some worker code in another script that consumes messages in the same queue.

As I check the management console:

enter image description here

I can see two connections, corresponding to the two scripts running different processes. If I click one of the connections:

enter image description here

About the title: Connection 172.21.0.1:56526 -> 172.21.0.2:5672:

172.21.0.1: what does this address mean?

56526: what does this port mean?

172.21.0.2: this should be the ip address of the rabbitMQ docker container

5672: this is the port specified in the docker-compose

How is 172.21.0.1:56526 related to one of my running script? When I run the script, it does not run on any port. so what is 172.21.0.1:56526?


Solution

  • Those connections are coming from somewhere outside of Docker; maybe another process on the host or a different system entirely. It's hard to say more than this.

    In TCP, both sides of the connection have an IP address and a port number. If you're connecting to Stack Overflow, you're sending the HTTP request to some address (for me, it looks like 151.101.1.69) and port 443, but the response data goes back to your local IP address and a randomly assigned port. RabbitMQ's wire protocol uses TCP as well, and the port 56526 is the randomly assigned port from the client. You'd see the same random ports looking at a non-container RabbitMQ console.

    Docker sets up a network address translation layer to provide container-private IP addresses. In your example, it looks like the Docker network is the IPv4 network 172.21.0.0/16, and the RabbitMQ broker has an arbitrary access on that network. A typical convention is for an external-facing router to have the first address on the network, and Docker sets this up as well; 172.21.0.1 is the address corresponding to the host, in this case.

    The way Docker port mappings work internally tends to lose the actual origin address. There's a connection from somewhere to the host at the first mapped port number, and a connection from Docker to the second port number, but the two connections lose a direct association. This very occasionally matters for diagnostics and not-especially-secure IP ACLing; see for example How can I access (forward) the public HTTP request IP address inside a docker compose network?.

    So those parts are: