Hello
Have developed small asp.net core 8.0 web app. This app needs a sql database. On my docker-compose file I have:
version: ‘2’
services:
db:
container_name: TradingZaimDb
image: Microsoft Artifact Registry
environment:
SA_PASSWORD: mypassword
ACCEPT_EULA: Y
MSSQL_MEMORY_LIMIT_MB: 2048
volumes:
- Trading_Db:/var/opt/mssql
networks:
- TradingDb
labels:
- traefik.enable=false
restart: unless-stopped
trading:
image: way76/trading_zaim:latest
container_name: TradingZaimWeb
depends_on:
- db
restart: unless-stopped
environment:
- ConnectionStrings__Default=“Server=TradingZaimDb;Database=Tra222;User Id=sa;Password=xxxxxx;”
- ASPNETCORE_HTTP_PORTS=80
labels:
- “traefik.enable=true”
- “traefik.http.routers.trading.rule=Host(txxxxt)”
- “traefik.http.routers.trading.tls=true”
- “traefik.http.routers.trading.tls.certresolver=lets-encrypt”
- “traefik.http.routers.trading.entrypoints=websecure”
networks:
- TradingDb
- traefik
volumes:
Trading_Db:
external: true
networks:
traefik:
external: true
TradingDb:
external: true
Even my .net core application starts up It cann’t connect to db. I get always this error
System.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 connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
Have tried every combination of connection string but there is no way to connect between containers. I tried also to connect from tradingweb container to db container using telnet and it’s working. Ping between containers by ip and name works correctly. H ave no idea what to do. Any help appreciated.