Skip to content

fix #7916 by using DOTNET_RUNNING_IN_CONTAINERS env var to detect container #9903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

analogrelay
Copy link
Contributor

Fixes #7916

I was assigned this back before @natemcmaster got back :). Finally just decided to do it rather than punting it around. Testing this looks tricky, I'll do a quick manual pass once it lands in the SDK. It's a pretty simple change.

All the official .NET Core images set this environment variable (Windows and Linux) so it should serve as a reasonable first thing to look for and make us a little more resiliant to running in other container runtimes.

@analogrelay analogrelay added the area-dataprotection Includes: DataProtection label May 1, 2019
@analogrelay analogrelay added this to the 3.0.0-preview6 milestone May 1, 2019
@@ -11,13 +11,13 @@ namespace Microsoft.AspNetCore.DataProtection.Internal
{
internal static class DockerUtils
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as we're at it, rename to ContainerUtils?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought about that. I'll do it :)

Copy link
Contributor

@blowdart blowdart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me

@analogrelay
Copy link
Contributor Author

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact [email protected].

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2450

@analogrelay
Copy link
Contributor Author

The remote name could not be resolved: 'xsp2tfsprodcus2file0.queue.core.windows.net'

:( Will retrigger when Azure is feeling less under-the-weather

@analogrelay analogrelay self-assigned this May 3, 2019
@analogrelay
Copy link
Contributor Author

@aspnet-hello
Copy link

This comment was made automatically. If there is a problem contact [email protected].

I've triaged the above build. I've created/commented on the following issue(s)
https://github.com/aspnet/AspNetCore-Internal/issues/2481

@analogrelay analogrelay merged commit 557bbf7 into master May 6, 2019
@ghost ghost deleted the anurse/7916-dataprotect-use-env-var-to-detect-container branch May 6, 2019 18:55
{
// Official .NET Core images (Windows and Linux) set this. So trust it if it's there.
if(string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINERS"), "true", StringComparison.OrdinalIgnoreCase))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo here, instead of DOTNET_RUNNING_IN_CONTAINERS it should be DOTNET_RUNNING_IN_CONTAINER.

See, e.g. https://github.com/dotnet/dotnet-docker/blob/master/2.1/runtime-deps/stretch-slim/amd64/Dockerfile#L21 for where it is set, or e.g. https://www.hanselman.com/blog/DetectingThatANETCoreAppIsRunningInADockerContainerAndSkippableFactsInXUnit.aspx for another source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should just check both then :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I see that the plural is deprecated. Will update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dataprotection Includes: DataProtection
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data Protection key generation warnings should also happen on Kubernetes
5 participants