Skip to content

Commit 20e85ba

Browse files
fix: handle stopped containers more gracefully when reuse is enabled
1 parent 3298e9a commit 20e85ba

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

docker.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ func (p *DockerProvider) findContainerByName(ctx context.Context, name string) (
12711271

12721272
// Note that, 'name' filter will use regex to find the containers
12731273
filter := filters.NewArgs(filters.Arg("name", fmt.Sprintf("^%s$", name)))
1274-
containers, err := p.client.ContainerList(ctx, container.ListOptions{Filters: filter})
1274+
containers, err := p.client.ContainerList(ctx, container.ListOptions{All: true, Filters: filter})
12751275
if err != nil {
12761276
return nil, fmt.Errorf("container list: %w", err)
12771277
}
@@ -1369,6 +1369,17 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
13691369
lifecycleHooks: []ContainerLifecycleHooks{combineContainerHooks(defaultHooks, req.LifecycleHooks)},
13701370
}
13711371

1372+
if p.config.RyukDisabled {
1373+
// ryuk disabled, ensure the container we are about to reuse is running
1374+
if c.State != "running" {
1375+
// found container to reuse, but it is not in state running
1376+
fmt.Println("Attempting to start: " + req.Name + " in state: " + c.State)
1377+
if err := dc.Start(ctx); err != nil {
1378+
return dc, fmt.Errorf("start container %s in state %s: %w", req.Name, c.State, err)
1379+
}
1380+
}
1381+
}
1382+
13721383
err = dc.startedHook(ctx)
13731384
if err != nil {
13741385
return nil, err

0 commit comments

Comments
 (0)