This is my appsettings.Production.json file, I am using a different port number than the default.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Server=docker-demo-sqlserver,1432;Database=DockerComposeDemo;User=sa;Password={0};TrustServerCertificate=True"
}
}
And this is my docker-compose file
version: '3.8'
services:
docker-demo-web-api:
container_name: docker-demo-web-api-container
build:
context: .
dockerfile: DockerDemoWebApi/Dockerfile
environment:
- MSSQL_SA_PASSWORD=Password1*
ports:
- "5000:8080"
depends_on:
- docker-demo-sqlserver
docker-demo-sqlserver:
container_name: docker-demo-sqlserver-container
image: mcr.microsoft.com/mssql/server:2022-latest
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=Password1*
ports:
- "1432:1432"
Although I use the same port number in the docker-compose file The app cannot find the docker-demo-sql server service.
When I change the port number to 1433 in the connection string, it works well even I don’t change the docker-compose port number(1432:1432
).
I don’t understand, it seems the app or SQL service doesn’t care the port number in the docker-compose file. Only When I change the port number 1433 to 1432 in the connection string it gives errors.