EF core connection string between two docker containers

Viewed 332

I have two containers:

  • .Net Core web API
  • MS SQL Server.

I'm using entity framework core for database operations, and I'm trying to connect to the database with a connection string.

Data Source={hostname};Database=...;Initial Catalog=...;User ID=...;Password=...;

What works:

  • hostname=localhost for updating locally with dotnet ef database update
  • hostname=172.X.X.X for communicating from API to the DB, where the ip address it the one docker assigns to the database

The problem is that I want to set the hostname to the name of the container. However, it doesn't work despite seeing a lot of examples online such as this article: https://blog.sixeyed.com/windows-weekly-dockerfile-17-connecting-containers/

Currently using Linux Docker on my windows machine. The containers are within the same "bridge" network.

0 Answers
Related