0

我正在尝试使用 docker compose 在 Windows 容器中运行带有 SQL Server 的 ASP.NET 应用程序。我能够从 asp.net 容器 ping SQL 容器 IP,但无法通过别名连接。如果我做错了什么,请告诉我。

我的撰写文件:

version: '3'

#services details
services:
  contosouniversity:
    build:
      context: .
    ports:
      - "5000:80"
    expose:
      - "5000"
    env_file:
      - ".env"
    depends_on: 
      - university_db

#data base details
  university_db:
    image: microsoft/mssql-server-windows-developer
    environment:
      sa_password: "sa"
      ACCEPT_EULA: "Y"
    ports:
      - "5672:1433"

#network configuration
networks:
  default:
    external:
      name: nat

ASP.NET web.config 文件具有连接字符串:

<add name="SchoolContext" 
         connectionString="Data Source=university_db;Initial Catalog=ContosoUniversity2;Integrated Security=false;User ID=sa;Password=sa" 
          providerName="System.Data.SqlClient" />
4

0 回答 0