I have these two containers
- SQL Server container
- .NET Core application container
I wanted to access the SQL Server from the application in order to run the application but keep getting the following error when I run the "docker-compose up" as shown below.
Error:
Application startup exception: System.AggregateException: One or more errors occurred. (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 connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server))
Here is my Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
COPY ./* App/
WORKDIR /App
EXPOSE 80
ENTRYPOINT ["dotnet", "webapp.ClientApp.dll"]
Note: The App was published on another machine that's why the docker file only contains the runtime image. Docker-compose file
version: "3"
services:
webapp:
build: .
ports:
- "8080:80"
depends_on:
- MS-SQL-Server
MS-SQL-Server:
image: mcr.microsoft.com/mssql/server:2019-latest
volumes:
- db-data:/var/lib/mysql
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: P@55w0rd2019
MSSQL_PASSWORD: P@55w0rd2019
MSSQL_PID: Express
ports:
- "1433:1433"
volumes:
db-data:
Connection string
"connectionstring": "Data Source=MS-SQL-Server;Initial Catalog=webappdb;Integrated Security= false;User ID=sa;Password=P@55w0rd2019;"
I have tried the service name for example "MS-SQL-Server" as you can see from the connection string also "localhost,1433" for the Data source=
So what am I missing here?