0

I am trying to run ASP.NET application with SQL server in windows container using docker compose. I am able to ping SQL container IP from asp.net container however not able to connect through alias name. Please let me know if I am doing anything wrong.

My compose file:

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 file has connection string:

<add name="SchoolContext" 
         connectionString="Data Source=university_db;Initial Catalog=ContosoUniversity2;Integrated Security=false;User ID=sa;Password=sa" 
          providerName="System.Data.SqlClient" />
Caramiriel
  • 7,029
  • 3
  • 30
  • 50
Manoj
  • 397
  • 2
  • 6
  • Login into running containers via `docker exec` and try to resolve name from powershell prompt – Gregory Suvalian Nov 04 '17 at 19:12
  • Hey Thanks for quick response. I tried but its failing. Please find log below:C:\inetpub\wwwroot>ping university_db Ping request could not find host university_db. Please check the name and try again. C:\inetpub\wwwroot>nslookup 74fa1763a1e9 Server: UnKnown Address: 172.25.208.1 *** UnKnown can't find 74fa1763a1e9: Server failed C:\inetpub\wwwroot>hostname 5d1a40194c9f C:\inetpub\wwwroot>nslookup 5d1a40194c9f Server: UnKnown Address: 172.25.208.1 *** UnKnown can't find 5d1a40194c9f: Server failed – Manoj Nov 04 '17 at 19:22
  • Appreciate if anyone can answer.. I am really stuck – Manoj Nov 08 '17 at 04:17
  • I suggest join `windows-containers` slack channel, you will get response there faster. Sample compose file below works fine for me for name resolution ```version: '3' #services details services: contosouniversity: image: microsoft/iis:nanoserver depends_on: - university_db #data base details university_db: image: microsoft/iis:nanoserver #network configuration networks: default: external: name: nat – Gregory Suvalian Nov 09 '17 at 00:52
  • The issue got resolved.. I think issue happened because I had installed DNS and DHCP server on same machine.. I did fresh installation of windows server and docker... it's working fine now... thanks for your help... – Manoj Nov 09 '17 at 13:26

0 Answers0