I want to connect my application with MySQL by Docker-compose. But, when I go to https://localhost:5001/api/Contacts (my Api), it fails to connect to database (Error: ERR_SSL_PROTOCOL_ERROR).
Here is my Docker-compose:
services:
mysql:
image: mysql
restart: always
volumes:
- ./setup.sql:/docker-entrypoint-initdb.d/setup.sql
- dbdata:/var/lib/mysql
environment:
MYSQL_ROOT_USER: root
MYSQL_ROOT_PASSWORD: admin
ports:
- 3307:3306
webapi:
image: webapi
build: .
restart: always
depends_on:
- mysql
ports:
- 5001:80
volumes:
dbdata:
Here is my Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DotnetCoreTrainingContext>(options =>
.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
new MySqlServerVersion(new Version())));
services.AddControllers();
}
Here is my appsettings.json:
"ConnectionStrings": {
"DefaultConnection": "server=mysql;user=root;password=admin;port=3307;database=DotnetCoreTraining;sslmode=none;"
}
How can I set server=mysql (name of MySQL image on Docker in my computer) in ConnectionStrings?