<p>I have 3 configs in service:</p>
<pre class="lang-py prettyprint-override"><code>1 - appsettings.development.json
2 - appsettings.testing.json
3 - appsettings.production.json
</code></pre>
<p>And i have 3 launch settings for them as well in <code>launchsettings.json</code>:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;profiles&quot;: {
        &quot;DevelopmentDockerProfile&quot; {
            &quot;commandName&quot;: &quot;Docker&quot;,
            &quot;environmentVariables&quot;: {
                &quot;DOTNET_ENVIRONMENT&quot;: &quot;development&quot;
            }
        },
        &quot;ProductionDockerProfile&quot; {
            &quot;commandName&quot;: &quot;Docker&quot;,
            &quot;environmentVariables&quot;: {
                &quot;DOTNET_ENVIRONMENT&quot;: &quot;production&quot;
            }
        },
        &quot;TestingDockerProfile&quot; {
            &quot;commandName&quot;: &quot;Docker&quot;,
            &quot;environmentVariables&quot;: {
                &quot;DOTNET_ENVIRONMENT&quot;: &quot;testing&quot;
            }
        }
    }
}
</code></pre>
<p>And i can normally run service, using correct configuration only on local machine.</p>
<p>I can not push <code>DOTNET_ENVIRONMENT</code> variable with service when publishing.</p>
<p>Is there any way to bind environment variable to <code>publishProfile.pubxml</code> or whatever else, that environment variable <code>DOTNET_ENVIRONMENT</code> will magically appear in docker service on host machine?</p>

<h2>Short answer</h2>
<p>No, there is no such option.</p>
<h2>Longer one</h2>
<p>First of all, you can easily set environment variables using <code>Environment.SetEnvironmentVariable(&quot;name&quot;, &quot;value&quot;)</code>. But that's probably not what you want.</p>
<p>What you might want is to configure environment variables in configs for container/orchestration tool you use, either set in docker command line (<code>docker run -e VARIABLE_NAME=value</code>) or in <code>docker-compose.yml</code> for Docker Compose or in service YAML config for k8s.</p>
