RabbitMQ Connect Failed: Broker unreachable – Docker image

I have installed this rabbitmq image ( tag : rabbitmq:3-management )

Used below command to setup container on my machine

docker run --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management

I can see container is up and running using docker ps command


RabbitMQ management portal is also up and running on port 8080

enter image description here

.Net Core 2.2 code

Below is piece of .Net core code to connect to create a connection

class Program
    static void Main(string[] args)
        Console.WriteLine("Hello World!");

        var factory = new ConnectionFactory() { HostName = "localhost" };
        factory.Port = 8080;
        factory.UserName = "guest";
        factory.Password = "guest";

        //Getting exception while creating connection 
        //RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'

        using (var conn = factory.CreateConnection())


        //I am having simillar issue with MassTransit
        //var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
        //  cfg.Host(new Uri(@"rabbitmq://localhost:8080/my-rabbit"), host =>
        //   {
        //       host.Username("guest");
        //       host.Password("guest");
        //   });




I am not able to create a connection and getting below exception:

RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'

Do I need to configure container with any other command or pass any additional environment variable while creating container?

Source: StackOverflow