João Amorim
João Amorim

Reputation: 81

Cannot access RabbitMQ UI on docker container

I'm currently working on a project where I have a virtual machine on Microsoft Azure and I'm trying to have multiple Docker containers to be accessed through different routes with the help of a Traefik reverse proxy. Besides the reverse-proxy, the first service I need to have is RabbitMQ and I should be able to access its user-interface on a /rmq route. Right now, I have the following docker-compose file to build both services:

version: "3.5"
services:
  rabbitmq:
    image: rabbitmq:3-alpine
    expose:
      - 5672
      - 15672
    volumes:
      - ./rabbit/enabled_plugins:/etc/rabbitmq/enabled_plugins
    labels:
      - traefik.enable=true
      - traefik.http.routers.rabbitmq.rule=Host(`HOST.com`) && PathPrefix(`/rmq`)
      # needed, when you do not have a route "/rmq" inside your container (according to https://stackoverflow.com/questions/59054551/how-to-map-specific-port-inside-docker-container-when-using-traefik)
      - traefik.http.routers.rabbitmq.middlewares=strip-docs
      - traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq
      - traefik.port=15672
    networks:
      - proxynet

  traefik:
    image: traefik:2.1
    command: --api=true     # Enables the web UI
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro
    ports:
      - 80:80
      - 443:443
    labels:
      traefik.enable: true
      traefik.http.routers.traefik.rule: "Host(`HOST.com`)"
      traefik.http.routers.traefik.service: "api@internal"
    networks:
      - proxynet

And this is the content of my traefik.toml file:

logLevel = "DEBUG"
debug = true

[api]
  dashboard = true
  insecure = false
  debug = true

[providers.docker]
  endpoint = "unix:///var/run/docker.sock"
  watch = true

[entryPoints]
  [entryPoints.web]
    address = ":80"

  [entryPoints.web-secure]
    address = ":443"

[log]
  level = "DEBUG"
  format = "json"

The enabled_plugins file specifies which RabbitMQ plugins should be activated. Here, I have the rabbitmq_management plugin (among others), which I think is needed to access the RabbitMQ UI. I even checked the logs of the RabbitMQ container and apparently the rabbitmq_management was properly started:

rabbitmq_1         | 2021-01-30 15:50:30.538 [info] <0.730.0> Server startup complete; 7 plugins started.
rabbitmq_1         |  * rabbitmq_stomp
rabbitmq_1         |  * rabbitmq_federation_management
rabbitmq_1         |  * rabbitmq_mqtt
rabbitmq_1         |  * rabbitmq_federation
rabbitmq_1         |  * rabbitmq_management
rabbitmq_1         |  * rabbitmq_web_dispatch
rabbitmq_1         |  * rabbitmq_management_agent
rabbitmq_1         |  completed with 7 plugins.
rabbitmq_1         | 2021-01-30 15:50:30.539 [info] <0.730.0> Resetting node maintenance status

With these configurations running with docker-compose up, if I try to access HOST.com/rmq, I get a 502 (Bad Gateway) error on the console of my browser. And initially, this was where I was stuck. However, after searching for some help online, I found a different way to specify the traefik port on the RabbitMQ container labels (traefik.http.services.rabbitmq.loadbalancer.server.port=15672) and, with this modification, I don't have the Bad Request error anymore, but I get a lot of ERR_ABORTED 404 (Not Found) errors on the console of my browser (the list bellow does not contain all the errors):

rmq:7 GET http://HOST.com/js/ejs-1.0.min.js net::ERR_ABORTED 404 (Not Found)
rmq:18 GET http://HOST.com/js/charts.js net::ERR_ABORTED 404 (Not Found)
rmq:19 GET http://HOST.com/js/singular/singular.js net::ERR_ABORTED 404 (Not Found)

Refused to apply style from 'http://HOST.com/css/main.css' because its MIME type ('text/plain') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

rmq:27 Uncaught ReferenceError: sync_get is not defined at rmq:27

I don't have much experience with this kind of projects and I don't know if I'm doing something wrong or if there's something missing in these configurations or on the configurations of the virtual machine itself. Do you know what I should do to be able to access the RabbitMQ UI with the URL HOST.com/rmq ?

If I get this running properly, I think I would also be able to configure Docker to only allow access to the Traefik UI with a route such as HOST.com/dashboard, instead of accessing it only with the URL without any routes.

Thanks in advance!

Upvotes: 3

Views: 4050

Answers (2)

Jo&#227;o Amorim
Jo&#227;o Amorim

Reputation: 81

Solved it. I don't know why, but when I used the configuration traefik.http.services.rabbitmq.loadbalancer.server.port=15672, I changed the order of the lines traefik.http.routers.rabbitmq.middlewares=strip-docs and traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq, making the prefix appear before the middleware. Changed that and now I can access the RabbitMQ UI on HOST.com/rmq. So my final docker-compose was this:

version: "3.5"
services:
  rabbitmq:
    image: rabbitmq:3-alpine
    expose:
      - 5672
      - 15672
    volumes:
      - ./rabbit/enabled_plugins:/etc/rabbitmq/enabled_plugins
    labels:
      - traefik.enable=true
      - traefik.http.routers.rabbitmq.rule=Host(`HOST.com`) && PathPrefix(`/rmq`)
      # needed, when you do not have a route "/rmq" inside your container (according to https://stackoverflow.com/questions/59054551/how-to-map-specific-port-inside-docker-container-when-using-traefik)
      - traefik.http.routers.rabbitmq.middlewares=strip-docs
      - traefik.http.middlewares.strip-docs.stripprefix.prefixes=/rmq
      - traefik.http.services.rabbitmq.loadbalancer.server.port=15672
    networks:
      - proxynet

  traefik:
    image: traefik:2.1
    command: --api=true     # Enables the web UI
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro
    ports:
      - 80:80
      - 443:443
    labels:
      traefik.enable: true
      traefik.http.routers.traefik.rule: "Host(`HOST.com`)"
      traefik.http.routers.traefik.service: "api@internal"
    networks:
      - proxynet

I'll mark this question as solved, but if you know why the order of these 2 lines matters, please explain for future reference.

Thanks!

Upvotes: 2

lahwran
lahwran

Reputation: 597

Trace of how I determined an answer to suggest for this question, given that I haven't used the specific tools:

By searching rabbitmq admin url, I found the rabbitmq management docs page, which near the top, mentions support of a path prefix setting. I searched the page for that, and under the relevant heading, found that you likely will need to set this setting in your rabbitmq config:

management.path_prefix = /rmq

So, to apply it to your docker config, I looked up the rabbitmq docker image, which discusses that configuration files need to be injected via a bind mount, or can be provided via an esoteric erlang config thing which I'd personally not mess with. Therefore, the steps I'd follow from here would be:

  1. look in the existing rabbitmq image to find out what the default config file in /etc/rabbitmq/rabbitmq.conf is, eg by running docker-compose run rabbitmq cat /etc/rabbitmq/rabbitmq.conf, or an appropriate docker cp command if it turns out rabbitmq sets a docker ENTRYPOINT which prevents use of shell commands on the image command line
  2. add a volume just like you have with enabled plugins but move it one directory upward, mapping rabbit/ to /etc/rabbitmq/, and then put the default config from the container in rabbit/
  3. add that line to the config file

With any luck that should at least get you closer. I'm curious to hear how it goes!

By the way, while looking at the rabbitmq docker image docs, I discovered that there are special tags for if you need management interface support. You may find that you need to switch to one of those instead of plain 3-alpine in order for this to work, eg rabbitmq:3-management-alpine.

Upvotes: 0

Related Questions