-
Notifications
You must be signed in to change notification settings - Fork 769
Open
Labels
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
If you point to a bind mount path that doesn't exist. (e.g. a drive that doens't exist on your machine), the contaienr will FailToStart, but without writing any logs - neither via tests, nor via the Dashboard, or the AppHostConsole
var container = builder.AddContainer("ddd", "nginx")
.WithBindMount("X:\\invalid\\path", "/mtn/whatever");Expected Behavior
There should be some kind of log output - somthing similar to what you get if you run docker run --mount type=bind,src=x:\invalid\path,dst=/mnt/whatever nginx
Error response from daemon: mkdir x:\invalid: The system cannot find the path specified.
See 'docker run --help'.
Steps To Reproduce
[Fact]
public async Task BindMountDoesNotExist()
{
using var cts = DefaultCancellationTokenSource();
await using var builder = DistributedApplicationTestingBuilder.Create();
var container = builder.AddContainer("nginx", "nginx")
.WithBindMount("X:\\invalid\\path", "/mtn/whatever");
AddFakeLogging(container);
await using var app = builder.Build();
await app.StartAsync(cts.Token);
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.FailedToStart, cts.Token);
var snapshot = app.Services.GetFakeLogCollector().GetSnapshot();
Assert.True(snapshot.Any());
Assert.Contains("docker: Error response from daemon: mkdir x:\\invalid: The system cannot find the path specified.", snapshot[0].Message);
}Exceptions (if any)
No response
.NET Version info
No response
Anything else?
This seems to be very specific to bind mounts. Various other failure scenarios do output some kind of error log consistently:
[Fact]
public async Task BadContainerArg()
{
using var cts = DefaultCancellationTokenSource();
await using var builder = DistributedApplicationTestingBuilder.Create();
var container = builder.AddContainer("container", "nginx")
.WithContainerRuntimeArgs("--illegal");
AddFakeLogging(container);
await using var app = builder.Build();
await app.StartAsync(cts.Token);
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.FailedToStart, cts.Token);
// Asert on ILogger `{builder.Environment.ApplicationName}.Resources.container`
// Expected Log: "unknown flag: --illegal"
var snapshot = app.Services.GetFakeLogCollector().GetSnapshot();
Assert.Contains("unknown flag: --illegal", snapshot[0].Message);
}
[Fact]
public async Task BadImage()
{
using var cts = DefaultCancellationTokenSource();
await using var builder = DistributedApplicationTestingBuilder.Create();
var container = builder.AddContainer("container", "does-not-exist")
.WithImageRegistry("does.not.exist.internal");
AddFakeLogging(container);
await using var app = builder.Build();
await app.StartAsync(cts.Token);
await app.ResourceNotifications.WaitForResourceAsync(container.Resource.Name, KnownResourceStates.FailedToStart, cts.Token);
var snapshot = app.Services.GetFakeLogCollector().GetSnapshot();
Assert.Contains("Unable to find image 'does.not.exist.internal/does-not-exist:latest' locally", snapshot[0].Message);
Assert.Contains("Error response from daemon", snapshot[1].Message);
}