Home > Software design >  Docker with rabbitmq networking
Docker with rabbitmq networking

Time:12-30

I have trouble understanding how docker port mapping works. I have a docker-compose file with a couple of containers, one of them is a rabbitmq service.

The docker-compose file is:

version: "3.9"
volumes:
  test:
    external: true

services:
  rabbitmq3:
      container_name: "rabbitmq"
      image: rabbitmq:3.8-management-alpine
      environment:
          - RABBITMQ_DEFAULT_USER=myuser
          - RABBITMQ_DEFAULT_PASS=mypassword
      ports:
          # AMQP protocol port
          - '5671:5672'
          # HTTP management UI
          - '15671:15672'    

So the container runs using docker compose up, no problem. But when I access the rabbitmq management plugin using container_ip:15671 or container_ip:15671, I don't get anything. But when I access it using 127.0.0.1:15672, I can access the management plugin.

It probably is a stupid question but how can I access the container service using localhost?

CodePudding user response:

The port sematic is as such <HOST_PORT>:<CONTAINER_PORT>. So -p 15671:15672 implies that the container port 15672 is mapped to the port 15671 on your machine.

Based on your docker compose file, the ports 5671 and 15671 are exposed on your machine.

The management portal can be accessed using http://localhost:15671 and the rabbitmq service can be used using the http://localhost:5671.

The IP 127.0.0.1 is localhost.

  • Related