Muhammad Rehan Saeed
Muhammad Rehan Saeed

Reputation: 38457

Run ASP.NET Core App in Docker Running as Custom User

I have an ASP.NET Core app connecting to a database using Integrated Security=True in the connection string, so that the credentials of the user running the app are used to connect to the database and so that I don't have to add a username and password User Id=username;Password=password in the connection string.

How can I run a Docker container of the above app using a user account in my domain. Is this even a thing I can do? If so, is it still a recommended approach? This seems possible using Windows containers but what about linux?

Upvotes: 5

Views: 1462

Answers (1)

Juan G Carmona
Juan G Carmona

Reputation: 2208

As someone commented on your question you can't do so because are two separate virtual machines runnign in your network. Also the SQL Server image for docker is linux based so it would make it more complex. What i'd do (and my team is alredy doing) is to have a sa SQL account and:

1.- In docker-compose.yml:

 sqlserver:
    image: microsoft/mssql-server-linux:latest
    container_name: sqlserver
    volumes:
      - mssql-server-linux-data:/var/opt/mssql/data
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=MySaPasswordIsHere
    ports:
      - "1433:1433"

2.- And in my conection string (s) looks like:

"MyServiceThatUsesSqlServer": {
      "MyConnectionString": "Server=sqlserver;Database=MyDatabaseName;User Id=sa;Password=MySaPasswordIsHere;"
    },

I hope it helps you to solve this issue.

PS: a very recent possible approach to "Active Directory Authentication with SQL Server on Linux" is explained here: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-active-directory-authentication

Upvotes: 2

Related Questions