Skip to content

Commit 046c3ec

Browse files
authored
docker: Restart container if it's found but not running already (#136)
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
1 parent 0293426 commit 046c3ec

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/container/docker/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,16 @@ func (c *Client) handleExistingContainer(
10621062
// Compare configurations
10631063
if compareContainerConfig(&info, desiredConfig, desiredHostConfig) {
10641064
// Configurations match, container can be reused
1065+
1066+
// Check if the container is running
1067+
if !info.State.Running {
1068+
// Container exists but is not running, start it
1069+
err = c.client.ContainerStart(ctx, containerID, container.StartOptions{})
1070+
if err != nil {
1071+
return false, NewContainerError(err, containerID, fmt.Sprintf("failed to start existing container: %v", err))
1072+
}
1073+
}
1074+
10651075
return true, nil
10661076
}
10671077

0 commit comments

Comments
 (0)