title: How can I pass the exit code of a dotnet core application out of a docker container
body: <p><strong>This is no longer an issue</strong></p>
  
  <p>The problem was most likely caused by some caching problem in Visual Studio.
  It was fixed by recreating the solution and re-adding Docker support.</p>
  
  <p>=========================================================================</p>
  
  <p>I have a small dotnet core application that is supposed to help with end to end tests.</p>
  
  <p>To be able to integrate it with our CI pipeline I put it into a docker container 
  and up to this point things are working out OK.</p>
  
  <p>Now the problem is that docker container does not exit with the same code as the application does.</p>
  
  <p>I assume this is because the application is encapsulated by the dotnet runtime, so even if the application exits with a non-zero code the actual entry point (<code>dotnet</code>) as defined in the <code>Dockerfile</code></p>
  
  <pre><code>ENTRYPOINT ["dotnet", "DataComparerCli.dll"]
  </code></pre>
  
  <p>exits with <code>0x0</code> and this is what is used as the exit code of the container.</p>
  
  <p>I tried to work around this by having the application store its exit code in an environment variable and creating a shell script as entry point which then calls dotnet in turn and uses the application's exit code as its own but this currently fails.</p>
  
  <pre><code>#!/bin/bash
  
  dotnet /app/path/to/dll/DataComparerCli.dll
  exit $DataComparerExitCode
  
  </code></pre>
  
  <p>It feels like I'm using a (broken) crutch and that this is the reason why I can't get this to work.</p>
  
  <p>Is this the a good approach and I'm just having issues with the bash script or are there better ways to get this to work?</p>
  
  <p><strong>UPDATE</strong>
  Apparently it is currently (version 3.1 preview) not possible to set environment variables that outlive the application on mac and linux:
  <a href="https://stackoverflow.com/a/44248788/2137237">https://stackoverflow.com/a/44248788/2137237</a></p>