Search code examples
azuredockerdocker-composerabbitmqtraefik

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!


Solution

  • 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!