title: Unable to connect to RabbitMQ started with Docker in a C# program (with RabbitMQ.Client)
body: <p>I started a RabbitMQ container following the article: <a href="https://docs.docker.com/samples/library/rabbitmq" rel="nofollow noreferrer">https://docs.docker.com/samples/library/rabbitmq</a> using the image including the management tool</p>
  
  <pre><code>docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management
  </code></pre>
  
  <pre class="lang-sh prettyprint-override"><code>docker container ls --all
  CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS
           NAMES
  8a42bb749074        rabbitmq:3-management   "docker-entrypoint.s…"   8 hours ago         Up 8 hours          4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080-&gt;15672/tcp   some-rabbit
  </code></pre>
  
  <p>I can access the management tool via <a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a></p>
  
  <p>I then created the most basic C# Project ever following <a href="https://www.rabbitmq.com/tutorials/tutorial-one-dotnet.html" rel="nofollow noreferrer">that article</a> to communicate with my local instance of RabbitMQ:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using System.Globalization;
  using RabbitMQ.Client;
  
  namespace RabbitCSharp
  {
      public static class Program
      {
          public static void Main(params string[] args)
          {
              var factory = new ConnectionFactory
              {
                  HostName = "localhost"
              };
              using (var connection = factory.CreateConnection())
              {
                  using (var channel = connection.CreateModel())
                  {
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>But unfortunately ran in the following error:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Unhandled Exception: RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---&gt; System.AggregateException
  : One or more errors occurred. (Connection failed) ---&gt; RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed ---&gt; System.Net.Internals.S
  ocketExceptionFactory+ExtendedSocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5672
     at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.Socket.&lt;&gt;c.&lt;ConnectAsync&gt;b__272_0(IAsyncResult iar)
  --- End of stack trace from previous location where exception was thrown ---
     at RabbitMQ.Client.TcpClientAdapter.ConnectAsync(String host, Int32 port)
     at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, Int32 millisecondsTimeout)
     at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, Int32 timeout)
     --- End of inner exception stack trace ---
     at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 timeout, AddressFamily fami
  ly)
     at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func`2 socketFactory, Int32 connectionTimeout, Int32 readTimeout, Int32 wri
  teTimeout)
     at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)
     at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
     --- End of inner exception stack trace ---
     at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func`2 selector)
     at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints)
     at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
     --- End of inner exception stack trace ---
     at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
     at RabbitCSharp.Program.Main(String[] args) in C:\Users\eperret\Desktop\RabbitCSharp\RabbitCSharp\RabbitCSharp\Program.cs:line 14
  
  Process finished with exit code -532,462,766.
  </code></pre>
  
  <p>Not really sure to understand why the RabbitClient cannot make it through <code>127.0.0.1:5672</code></p>
  
  <p>Any idea?</p>