Skip to content

Commit 8588794

Browse files
authored
fix: Set container created, started, stopped time from inspect response (#1455)
1 parent 2a09374 commit 8588794

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Testcontainers/Containers/DockerContainer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ await _client.System.LogContainerRuntimeInfoAsync(ct)
458458
_container = await _client.Container.ByIdAsync(id, ct)
459459
.ConfigureAwait(false);
460460

461-
CreatedTime = DateTime.UtcNow;
461+
CreatedTime = _container.Created;
462462
Created?.Invoke(this, EventArgs.Empty);
463463
}
464464

@@ -520,7 +520,7 @@ await _configuration.StartupCallback(this, ct)
520520

521521
Logger.CompleteReadinessCheck(_container.ID);
522522

523-
StartedTime = DateTime.UtcNow;
523+
StartedTime = DateTime.TryParse(_container.State.StartedAt, null, DateTimeStyles.AdjustToUniversal, out var startedTime) ? startedTime : DateTime.UtcNow;
524524
Started?.Invoke(this, EventArgs.Empty);
525525
}
526526

@@ -556,7 +556,7 @@ await _client.StopAsync(_container.ID, ct)
556556
_container = new ContainerInspectResponse();
557557
}
558558

559-
StoppedTime = DateTime.UtcNow;
559+
StoppedTime = DateTime.TryParse(_container.State.FinishedAt, null, DateTimeStyles.AdjustToUniversal, out var stoppedTime) ? stoppedTime : DateTime.UtcNow;
560560
Stopped?.Invoke(this, EventArgs.Empty);
561561
}
562562

0 commit comments

Comments
 (0)