Error when accessing from one dotnet core docker container to a mysql docker container

0

I tried to build an application consisting on DotNet Core and a MySQL docker containers using docker-compose.

I used Entity Framework and I succeeded making the connection and updating database via command with this connection string:

"server=127.0.0.1;database=hellofreshgo;user=root;password=hellofreshgo;Port=3306"

But when I dockerize or containerize my netcore app and try to retrive data and connect with my mysql container with this connection string and the the following docker-compose file:

"server=mysql;database=hellofreshgo;user=root;password=hellofreshgo;Port=3306" version: '3.4'

services:
  hfgo.backendtest.api:
    image: ${DOCKER_REGISTRY-}hfgobackendtestapi
    build:
        context: .    
        dockerfile: src/Presentations/HFGO.BackendTest.API/Dockerfile
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:8080;http://+:80
    volumes:
        - ./:/server/http
    links:
        - mysql
    ports:
        - "8080:8080"
    depends_on:
        - mysql
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro


  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
        - "3306:3306"
    environment:
        LC_ALL: C.UTF-8
        MYSQL_ROOT_PASSWORD: hellofreshgo
        MYSQL_DATABASE: hellofreshgo

I got the following error:

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. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.AggregateException: One or more errors occurred. (Connection refused 127.0.0.1:3306)

Before someone ask yes as the error mentions, I already added EnableRetryOnFailure() to UseMySQL()

mysql
asp.net
docker
asp.net-core
docker-compose
asked on Stack Overflow Aug 25, 2020 by Guillem Soler Suetta • edited Aug 25, 2020 by Guillem Soler Suetta

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0