title: .NET Core application in docker cannot connect to mysql server
body: <p>I have a .NET Core application running in docker.</p>
  <p>For the connection string:</p>
  <pre><code> &quot;Server=localhost;port=3306;database=xxxxx;uid=xxxxx;password=xxxxx;&quot;
  </code></pre>
  <p>When it connects to a non-docker mysql server on the same centos server,
  it shows:</p>
  <pre><code>MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---&gt; System.AggregateException: One or more errors occurred. (Connection refused 127.0.0.1:3306) ---&gt; System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.0.1:3306
     at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
     at System.Net.Sockets.Socket.MultipleAddressConnectCallback(IAsyncResult result)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.TcpClient.&lt;&gt;c.&lt;ConnectAsync&gt;b__28_1(IAsyncResult asyncResult)
     at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
     --- End of inner exception stack trace ---
     at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
     at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
     at MySql.Data.MySqlClient.NativeDriver.Open()
  ---&gt; (Inner Exception #0) System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused 127.0.0.1:3306
     at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)
     at System.Net.Sockets.Socket.MultipleAddressConnectCallback(IAsyncResult result)
  --- End of stack trace from previous location where exception was thrown ---
     at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
     at System.Net.Sockets.TcpClient.&lt;&gt;c.&lt;ConnectAsync&gt;b__28_1(IAsyncResult asyncResult)
     at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)&lt;---
  </code></pre>
  <p>However I have checked port 3306 is with LISTEN status.
  How can I fix this issue?</p>