In recent times I faced the question - how would I set up my development secrets like database passwords, connection strings, sensitive secret data without exposing them to the public world/git?

Visual Studio has a pretty nice feature to organize development secrets named User Secrets. Despite finding it useful to set up some of the appsettings.json substitutions, it's nearly useless when it comes to environment variable configuration used in docker-compose.

I tried several strange things like creating a bash script to populate envs from secrets.json, or adding docker arguments to .dcproj. It took me so long to make a working solution, and it was so dirty, so I end up using
env_file docker-compose configuration alongside with hiding the file from git.

    image: mongo:4.4.1-bionic
    restart: always
    - "27017:27017"
    - .env # placed in the same folder as docker-compose.yml

And .env file is just a plain text with environment variables you need as a
<key>=<value> pair:


And don't forget to add .env to your .gitignore file.

@@ -9,6 +9,7 @@

 # User-specific files (MonoDevelop/Xamarin Studio)

(OPTIONAL) I also find it useful to have a reference in my Visual Studio project to that file so I can edit it on demand.

  <Content Include="..\.env" LinkBase="envs" />