Docker-compose environment variables

I have dotnetcore 2 project, I need get compose environment:

In “IConfiguration configuration - environment variables” provider it is not found.

How get this value?


I have no idea what this means, if this an Exception please provide the full StackTrace and the source code that causes it.

Sorry for bad English :frowning:

I have a project which runs in a Docker environment

This is the initial project code:

public class Program {

    public static void Main(string[] args) {             
    public static IWebHost BuildWebHost(string[] args) =>

public class Startup {

    public IConfiguration Configuration { get; }
    public Startup(IConfiguration configuration) => Configuration = configuration;
    public void ConfigureServices(IServiceCollection services) {
    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
        if (env.IsDevelopment()) {
        app.UseServiceStack(new AppHost {
            AppSettings = new NetCoreAppSettings(Configuration)

My project uses Redis, so to run in the local environment I’m using docker-compose and I want to be able to take the address of the redis server docker-compose.yaml

This article States how you can obtain the environment settings in my project environment settings are already there, but the values from docker-compose missing;

Help please, how do I get the value from the docker-compose.yaml

Please ask questions on other Technologies you’re using on StackOverflow.

There’s nothing special about Docker Environment variables, if it was configured properly you can access them with .NET APIs:

// Anywhere
Console.WriteLine("Environment: " + Environment.GetEnvironmentVariable("EmailServer"));

// With .NET Core's Configuration:
Console.WriteLine("Configuration: " + Configuration["EmailServer"]);

// With ServiceStack IAppSettings API Configured with: new NetCoreAppSettings(Configuration) 
Console.WriteLine("AppSettings: " + AppSettings.GetString("EmailServer"));

By default .NET Core 2.0’s default WebHost.CreateDefaultBuilder(args) will automatically configure its configuration with .AddEnvironmentVariables() so you’ll be able to access Environment Variables with the APIs above by default.

If the above APIs are not returning the value there is something wrong with your Docker Compose setup, in which case you can ask for support on StackOverflow or in the comments section of the post you’re following.

The issue is that I created a project based on your template so I decided issue to discuss with you, if not your question is OK! Thank you for the examples you gave, I already tried, unfortunately does not work. Thank you for your time!