Skip to content

Commit

Permalink
Fixes #42741
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Jan 7, 2025
1 parent 49d9f1f commit 4f39d60
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/core/docker/build-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ C:\>dir
C:\>^C
```

> [!NOTE]
> This example only works on Windows containers. Linux containers don't have `cmd.exe`.
#### [Linux](#tab/linux)

In this example, `ENTRYPOINT` is changed to `bash`. The `exit` command is run which ends the process and stop the container.
Expand All @@ -519,6 +522,9 @@ root@9f8de8fbd4a8:/App# exit
exit
```

> [!NOTE]
> This example only works on Linux containers. Windows containers don't have `bash`.
---

## Essential commands
Expand Down
7 changes: 7 additions & 0 deletions docs/core/docker/snippets/9.0/Worker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Worker;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"profiles": {
"Worker": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true
},
"Container (.NET SDK)": {
"commandName": "SdkContainer"
}
},
"$schema": "https://json.schemastore.org/launchsettings.json"
}
23 changes: 23 additions & 0 deletions docs/core/docker/snippets/9.0/Worker/Worker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Worker;

public class Worker : BackgroundService
{
private readonly ILogger<Worker> _logger;

public Worker(ILogger<Worker> logger)
{
_logger = logger;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
}
await Task.Delay(1000, stoppingToken);
}
}
}
19 changes: 19 additions & 0 deletions docs/core/docker/snippets/9.0/Worker/Worker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Worker-2ecd8110-3fcc-4ccb-a1d6-952f1adba2c5</UserSecretsId>
<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<ContainerBaseImage>mcr.microsoft.com/dotnet/runtime:9.0</ContainerBaseImage>
<IsPublishable>True</IsPublishable>
<EnableSdkContainerSupport>True</EnableSdkContainerSupport>
<DockerfileContext>.</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
8 changes: 8 additions & 0 deletions docs/core/docker/snippets/9.0/Worker/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

0 comments on commit 4f39d60

Please sign in to comment.