Skip to content

Getting container id in container. Works with cgroup v1 and cgroup v2

License

Notifications You must be signed in to change notification settings

xiaomi7732/CGroupV2ContainerId

Repository files navigation

Get the container id

Package-Badge Download-Badge

Getting container id is important for logging. Let's get it.

Get Started

  • Add NuGet package
dotnet add package CodeWithSaar.Extensions.ContainerId --prerelease
  • Put container id in your telemetry
// Get container id.
string containerId = await ContainerService.GetContainerIdAsync();
// Log it.
_logger.LogInformation("This is some information from container: {containerId}", containerId);
  • Output:
info: TestClass[0] This is some information from container: 01d1ad1a7b528295f2d03619b35f995be9ddddcfd2a83c013df129aa6cc4d332

That's it. Start this repo if you like it.

Alternatively, dependency injection is also supported, refer to Use it with dependency injection.

Examples

About

Getting container id in container. Works with cgroup v1 and cgroup v2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages