Skip to content

Commit b32297d

Browse files
committed
add --wait option to start command
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent af8cac5 commit b32297d

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

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
}

docs/reference/compose_start.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ Starts existing containers for a service
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:------------|:-------|:--------|:--------------------------------|
10-
| `--dry-run` | `bool` | | Execute command in dry run mode |
8+
| Name | Type | Default | Description |
9+
|:-----------------|:-------|:--------|:---------------------------------------------------------------------------|
10+
| `--dry-run` | `bool` | | Execute command in dry run mode |
11+
| `--wait` | `bool` | | Wait for services to be running\|healthy. Implies detached mode. |
12+
| `--wait-timeout` | `int` | `0` | Maximum duration in seconds to wait for the project to be running\|healthy |
1113

1214

1315
<!---MARKER_GEN_END-->

docs/reference/docker_compose_start.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ long: Starts existing containers for a service
44
usage: docker compose start [SERVICE...]
55
pname: docker compose
66
plink: docker_compose.yaml
7+
options:
8+
- option: wait
9+
value_type: bool
10+
default_value: "false"
11+
description: Wait for services to be running|healthy. Implies detached mode.
12+
deprecated: false
13+
hidden: false
14+
experimental: false
15+
experimentalcli: false
16+
kubernetes: false
17+
swarm: false
18+
- option: wait-timeout
19+
value_type: int
20+
default_value: "0"
21+
description: |
22+
Maximum duration in seconds to wait for the project to be running|healthy
23+
deprecated: false
24+
hidden: false
25+
experimental: false
26+
experimentalcli: false
27+
kubernetes: false
28+
swarm: false
729
inherited_options:
830
- option: dry-run
931
value_type: bool

0 commit comments

Comments
 (0)