Skip to content

Commit 38c50c5

Browse files
committed
add --wait option to start command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent af8cac5 commit 38c50c5

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

cmd/compose/start.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"time"
2122

2223
"github.com/docker/cli/cli/command"
2324
"github.com/docker/compose/v5/pkg/api"
@@ -27,6 +28,8 @@ import (
2728

2829
type startOptions struct {
2930
*ProjectOptions
31+
wait bool
32+
waitTimeout int
3033
}
3134

3235
func startCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {
@@ -41,6 +44,10 @@ func startCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Back
4144
}),
4245
ValidArgsFunction: completeServiceNames(dockerCli, p),
4346
}
47+
flags := startCmd.Flags()
48+
flags.BoolVar(&opts.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
49+
flags.IntVar(&opts.waitTimeout, "wait-timeout", 0, "Maximum duration in seconds to wait for the project to be running|healthy")
50+
4451
return startCmd
4552
}
4653

@@ -54,9 +61,13 @@ func runStart(ctx context.Context, dockerCli command.Cli, backendOptions *Backen
5461
if err != nil {
5562
return err
5663
}
64+
65+
timeout := time.Duration(opts.waitTimeout) * time.Second
5766
return backend.Start(ctx, name, api.StartOptions{
58-
AttachTo: services,
59-
Project: project,
60-
Services: services,
67+
AttachTo: services,
68+
Project: project,
69+
Services: services,
70+
Wait: opts.wait,
71+
WaitTimeout: timeout,
6172
})
6273
}

0 commit comments

Comments
 (0)