我试图使用docker-compose构建一个由DotNet Core和MySQL docker容器组成的应用程序。
我使用了Entity Framework,并通过命令使用以下连接字符串成功建立了连接并更新了数据库:
“服务器= 127.0.0.1;数据库= hellofreshgo;用户=根;密码= hellofreshgo;端口= 3306”
但是当我对netcore应用进行dockerize或容器化并尝试检索数据并使用此连接字符串和以下docker-compose文件与mysql容器连接时:
“服务器= mysql;数据库= hellofreshgo;用户= root;密码= hellofreshgo;端口= 3306” 版本:“ 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
我遇到以下错误:
System.InvalidOperationException:引发了一个异常,该异常是 可能是由于短暂故障造成的。考虑启用瞬态错误 通过将“ EnableRetryOnFailure()”添加到“ UseMySql”调用来实现弹性。 ---> MySql.Data.MySqlClient.MySqlException(0x80004005):无法连接到任何指定的MySQL主机。 ---> System.AggregateException:发生一个或多个错误。 (连接 拒绝127.0.0.1:3306)
在出现错误提示之前,我已经将EnableRetryOnFailure()
添加到UseMySQL()