Reputation: 511
I have the following issue: I have the following docker-compose file
version: "3"
services:
web:
build: .
ports:
- "8000:80"
links:
- my-special-db
networks:
- demo-net
my-special-db:
image: "microsoft/mssql-server-windows-developer"
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- sa_password=demo
networks:
- demo-net
networks:
demo-net:
driver: nat
In the appsettings.Docker.json I have the following connection string: "ConnectionStrings": { "DefaultConnection": "Server=my-special-db;Database=ContosoUniversity3;Trusted_Connection=True;MultipleActiveResultSets=true" }
I've tried passing also the password, it doesn't work. What I'm doing wrong?
Upvotes: 0
Views: 970
Reputation: 3303
You need to add both services in a common network.
Please rede this document: Docker Networks
In each of your services:
networks:
- sql-net
In the end of the compose file:
networks:
sql-net:
driver: bridge
Then you'll be able to connect to the database through its container name, in your case my-special-db
The error reported by the OP suggests that it's running Windows 10. There is an open bug for it here
There are reports that using transparent
driver might work:
networks:
sql-net:
driver: transparent
You can also try using the legacy Link feature. Add this to the web
container:
web:
links:
- my-special-db
Upvotes: 1