ASP.NET Core MySQL connection docker-compose

0

I am using MySQL in the ASP.NET Core web application. The connection string :

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseMySQL("server=db;port=3306;user=root;password=Mysqlparola123;database=AppUserDb");
        }
    }

and Docker-compose yml file :

version: "3.1"

services:
  db:
    image: "mysql"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: Mysqlparola123
  webapp:
    build: .
    image: brandidentity
    ports:
        - "5001:5001"
    depends_on:
        - "db"
    links:
        - "db:db"

When docker-compose up, I am getting an error like this:

webapp_1  | Unhandled exception. System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.
webapp_1  |  ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
webapp_1  |  ---> System.Net.Sockets.SocketException (111): Connection refused
webapp_1  |    at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
webapp_1  |    at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext)
webapp_1  |    at System.Net.Sockets.Socket.PostOneBeginConnect(MultipleAddressConnectAsyncResult context)
mysql
docker
asp.net-core
docker-compose
asked on Stack Overflow Aug 30, 2020 by Onur Kayabaşı

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0