Build configuration for running ASP.NET applications within Linux containers using Mono.
ASP.NET application need not be ASP.NET Core, and image can be run within Linux container rather than Windows
-
Copy your published ASP.NET application into the
build
folder within this project. Yourweb.config
should be in the root ofbuild
-
Build and tag for docker. For example:
docker build -t mywebservicename .
-
Run the image. For example:
docker run -it -p 8080:80 mywebservicename
-
Test the image locally by accessing http://localhost:8080/
With the default setup if Web.config
changes the image be be rebuilt
and the container restarted. Using volumes it is possible to
dynamically change the configuration without a rebuild / restart.
The difficulty is the volume mounts occur on a folder basis not file
so the settings that you want to be dynamic must be moved into a
subfolder and referenced by Web.config
.
This is an example for <appSettings>
but should work for most
sections of Web.config
.
-
In
build
folder create a new folderconfig
-
Within the new folder copy your
<appSettings>
fromWeb.config
:<appSettings> <add key="foo" value="bar" /> </appSettings>
-
Remove
<appSettings>
fromWeb.config
and replace with:<appSettings configSource="config/appSettings.config"> </appSettings>
-
Ignore
build/config
within.dockerignore
:Dockerfile build/config/*
-
Build and tag for docker. For example:
docker build -t mywebservicename .
-
Run the image mounting the
config
folder:docker run -it -p 8080:80 -v $(pwd)/build/config/:/var/www/config/ mywebservicename
If kubernetes is used, a ConfigMap can be created that will mount in
/var/www/config/
allowing configuration to be updated without
restarting or rebuilding the pod