best way to configure / implement .NET web api, docker, mssql server

I come from an old way of doing this where we had connection strings in web.config or app.config. I'd like to redo one of my apps to take advantage of docker but I don't know the best way to go about doing this.
Hi
Say I have a web app that I provide to a few customers and currently they do the usual IIS install and change the web.config to point to another server's SQL server database for data storage.

I want to be able to now provide a docker container to each one and set it up so the web api points to the external sql server of their choice. The docker container contains both the front end in say angular or react and a .NET core web api with services.

What's the best way to configure it so I can setup the container and have it point to a specific sql server with the login credentials necessary for the web api to access it? I've been trying to find something to explain it to me.

Thanks for any help!
I have no idea how to run .NET applications in a Docker container. But the standard way of "parameterizing" a Docker container is setting up environment variables. For example, when you start a MySQL container, you set the desired database name and the database credentials via the corresponding environment variables.

See this example:
https://dbschema.com/2020/03/31/how-to-run-mysql-in-docker/

Note especially how they set environment variable MYSQL_ROOT_PASSWORD to configure the root password for the MySQL instance that will be running in the container. There are many more environment variables that can be set for the MySQL container. Please see here (section "Environment Variables") for details:
https://hub.docker.com/_/mysql?tab=description

The MySQL container only servers as an example here! The environment variables will of course be different for each "type" of container. Your .NET container could offer other environment variables.

Another option would be to pass a custom configuration file into the container. Again, the details are different for each "type" of container, but you'll find an example for the MySQL container.

The docker container contains both the front end in say angular or react and a .NET core web api with services.

It's probably better to have a separate container for each service and have your containers communicate via network ports. Have a look at docker compose for managing multi-container setups.
Last edited on
Topic archived. No new replies allowed.