Implement Container Readiness Check in Manager

- Added a loop in the ensureRunning method to wait for the Docker container to be in a running state before proceeding, enhancing reliability in container management.
- Included error handling for container inspection to ensure proper feedback in case of failures during the readiness check.
This commit is contained in:
Max 2026-01-29 19:38:03 +08:00
parent 55e43a7edd
commit 08e7ed36a3

View file

@ -231,6 +231,18 @@ func (m *Manager) ensureRunning(ctx context.Context, name string) error {
return fmt.Errorf("failed to start container: %w", err)
}
// Wait for container to be ready (inspect until running)
for i := 0; i < 30; i++ {
info, err := m.dockerClient.ContainerInspect(ctx, cont.ID)
if err != nil {
return fmt.Errorf("failed to inspect container: %w", err)
}
if info.State.Running {
break
}
time.Sleep(100 * time.Millisecond)
}
m.mu.Lock()
cont.Status = StatusRunning
cont.LastUsedAt = time.Now()