Skip to main content

12 Factor Config for .Net on Mono in a Docker

Recently I've been thinking about how to run a .Net application using Mono inside a Docker, along with this we'd like to use Twelve Factor config.

Whilst it is possible to use some library to access environment variables instead of using appSettings it becomes difficult for database and message broker URLs which other libraries may expect to find within the App.config or Web.config file.

The solution I came up with follows:

Build the application without an App.config moving the existing configuration file renaming it App.config.template

Substitute any environment variables you want with ${}.  E.g:

<amqp> <connections> <connection name="rabbit" server="${RABBITMQ_URL}" password="${RABBITMQ_PASSWORD}" /> </connections> </amqp>

Include within the Docker image a script named sub.sh similar to this and add it to /conf:

#!/bin/sh
while read line
do
    eval echo "$line"
done
Add your config template to /conf

Then in the DockerFile, if your CMD is:

CMD ["mono", "/app/foo.exe" ]
Change it to:

CMD /conf/sub.sh /conf/App.config.template > /app/App.config; mono /app/foo.exe
Now when you run your Docker image, pass in your environment variables as usual. In this case, I'd set the RABBITMQ_URL and the RABBITMQ_PASSWORD

You can also configure these in a file and pass it into the docker run command using --env-file

Comments

Stuart said…
If you use Monodevelop, or Xamarin Studio, there is a remote debugger add-in called SSH Debugger. You can find this in the built in add-in repo.

With this, you can automatically deploy, and debug your .NET apps just by setting the IP of the host (or container) You may need change the script a bit for docker if you don't have ssh inside a container.

I plan to do a video on it soon.

Project page here:https://github.com/logicethos/SSHDebugger

Popular posts from this blog

Howto: Ubuntu 8.10, Dell 5530, 3G/WWan and GPS

There is an updated howto on the Dell 5530 using my own python based monitoring tool at http://blog.bjw.me.uk/2009/03/dell-5530ericsson-f3507g-on-linux.html Introduction Here is a Howto document for getting the Dell 5530 wwan card working along with the onboard GPS under Ubuntu 8.10. This card does not work conveniently with the bundled Network Manager software, but replacing NetworkManager with other utilities will give the ability to get online using a pretty GUI and not have to resort to using wvdial and the command line... It should also work with the Ericsson f3507g as I believe the Dell 5530 is a rebadged version of this module. Check Hardware First you need to check the modem is detected correctly. On my computer, the modem is detected out of the box by the cdc_acm module and exposes three serial ports (/dev/ttyACM[0,1,2]) for communication. Check by running: dmesg | grep ACM Mine shows the following: [ 34.385302] cdc_acm 1-6:1.1: ttyACM0: USB ACM device [ ...

Linn DS Alarm Function

Update 2014 - An alternative to this is available on GitHub which uses Node.js and should be cross platform. Linn DS Playlist and Alarm Server Switching the radio on in the kitchen in the morning is a low priority amongst setting table, pouring cereals, carrying children, etc. The Sonos has an alarm clock facility which allows you to switch on the radio at a set time avoiding hassle of starting a controller. When I upgraded to my Linn Sneaky DS, I no longer had this function, though the remote control made it easy if I forgot to take my phone downstairs with me. Last week I decided to figure it out. I have a Linux machine which runs Ubuntu and runs all the media servers, backups and network shares. I decided to investigate how to control my DS from the command line. Conveniently, the DS can be controlled via a web api, so after reading the docs and a few examples I was able to switch off and on and change source via Postman (Chrome REST client). I then set about writing...

Howto: Node Red Subflow for Hue Bulbs

When writing some flows for Node-RED controlling my Philips Hue bulbs; I wanted to read from a bulb do some work then write that same colour back to the bulb. When you perform a GET on a bulb, you get all of the information, whilst good this means it is a bit more inconvenient to PUT that back into a bulb as that API has a slightly different resource shape where the colour mode is determined by which values are submitted. After using a group of nodes in one flow which did exactly this, I needed the same block in another flow. So I created a sub flow by selected those nodes, clicking the hamburger menu in the top right and choosing 'Subflows > Selection to Subflow'. This replaces the selected nodes with a single node which you can edit in a 'subflows' menu group in the left pane. Download this selection and make your own subflow: https://dl.dropboxusercontent.com/u/174818/HueInputToOutput.json?dl=1