sql-server - Docker SQL Server异常

标签 sql-server docker asp.net-core-webapi

在Docker容器中运行.NET Core 3.1 Web API项目时遇到SQL异常

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"

最佳答案

确保In SQL Server配置正确。此外,请检查以下链接:mssql-docker-issues

关于sql-server - Docker SQL Server异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62614394/

相关文章:

asp.net-core-mvc - 从 MVC Controller 在同一应用程序中使用 Web API

sql - Microsoft SQL - 识别重复项并分配唯一标识符

sql-server - 外部应用函数的性能

docker - 自定义 Hasura Docker 镜像

Azure 托管身份 token 无法从本地生成

c# - 当不同程序集中的 Startup.cs 时,ASP.NET Core Web API 返回 404

Python 数据帧到 SQL 数字正在四舍五入

c# - 将记录写入数据库并且仅输入每个字段的第一个字符

linux - 使用 sed 在 Docker 中插入第二行(在 shebang 下)

docker - 有没有办法将主机名添加到现有的 docker 容器?