title: Cannot connect to mysql db after docker compose up
body: <p>I created a container with a mysql database and the manual connection with a <code>.net</code> application works very good. Now I would use a <code>docker-compose</code> to build the mysql container and my <code>.net</code> application image automatically.</p>
  
  <p>My docker compose looks like that.</p>
  
  <pre><code>version: '3.1'
  
  networks:
    overlay:
  services:
    authentication_service:
      image: authentication_service:latest
      depends_on:
        - "authentication_service_db"
        - "adminer"
      build:
        context: .
        dockerfile: Dockerfile
      links:
        - authentication_service_db
      ports:
        - "5003:80"
      networks:
        - overlay
    authentication_service_db:
      image: mysql:8.0.3
      environment:
        MYSQL_ROOT_PASSWORD: secret
        MYSQL_DATABASE: authenticationdb
      ports:
        - 3305:3306
      restart: always
      volumes:
        - ./data-authentication:/var/lib/mysql
      networks:
        - overlay
  </code></pre>
  
  <p>When I start the application in development the connection string is printed and looks like that <code>server=localhost;Port=3305;Database=authenticationdb;Uid=root;Pwd=secret</code>. This works.</p>
  
  <p>When I run <code>docker-compose up  -d --build</code> it changes:
  <code>server=authentication_service_db;Port=3305;Database=authenticationdb;Uid=root;Pwd=secret;</code></p>
  
  <p>My connection test script:</p>
  
  <pre><code>private static void WaitForDbInit(string connectionString)
          {
              var connection = new MySqlConnection(connectionString);
              Console.WriteLine("Connecting with credentials: {0}", connectionString);
  
              var retries = 1;
              while (retries &lt; 5)
              {
                  try
                  {
                      Console.WriteLine("Connecting to db. Trial: {0}", retries);
                      connection.Open();
                      connection.Close();
                      break;
                  }
                  catch (MySqlException)
                  {
                      Thread.Sleep((int) Math.Pow(2, retries) * 1000);
                      retries++;
                  }
              }
          }
  </code></pre>
  
  <p>The Log:</p>
  
  <pre><code>Connecting to db. Trial: 1
  Connecting to db. Trial: 2
  Connecting to db. Trial: 3
  Connecting to db. Trial: 4
  [...]
  application startup exception: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
     at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 299
  </code></pre>
  
  <p>appsettings.json:</p>
  
  <pre><code>{
    "Logging": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "AllowedHosts": "*",
    "MysqlConnection": {
      "connectionString": "server=authentication_service_db;Port=3305;Database=authenticationdb;Uid=root;Pwd=secret;"
   }
  }
  </code></pre>
  
  <p>So I don't know how debug or what I can do next. I don't get a connection when I use docker compose. </p>