I had a SQL exception while I was running my .NET Core 3.1 Web API project in a Docker container
Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connection
version: "3.7"
services:
SQLServer:
image: mcr.microsoft.com/mssql/server
container_name: SQLServer
networks:
mynetwork:
aliases:
- db1.internal.prod.example.com
CRUD_JSON_API:
image: koccan9/crud_json_api:samplev3
container_name: "crud_json_api_sample"
restart: on-failure
build:
context: .
dockerfile: CRUD_JSON_API/Dockerfile
depends_on:
- SQLServer
networks:
mynetwork:
aliases:
- web1.internal.prod.example.com
volumes:
mssql-server-julie-data: {}
networks:
mynetwork:
driver: bridge
version: '3.7'
services:
SQLServer:
environment:
- MSSQL_SA_PASSWORD=xxx
- ACCEPT_EULA=Y
- MSSQL_PID=Developer
ports:
- "1433:1433"
volumes:
- ./data/mssql:/var/opt/mssql3
expose:
- 1433
CRUD_JSON_API:
links:
- SQLServer
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=http://0.0.0.0:80
- ConnectionString=${IDENTITY_DB:-Server=SQLServer;Database=DEV_CRUD_JSON_API;User Id=sa;Password=xxx}
ports:
- "5000:80"
Make sure that In SQL Server configuration is correct. Additionally check this link: mssql-docker-issues
User contributions licensed under CC BY-SA 3.0