mirror of
https://github.com/docker/compose.git
synced 2026-02-09 01:59:22 +08:00
add --wait option to start command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
committed by
Nicolas De loof
parent
af8cac5768
commit
b32297dccd
@@ -18,6 +18,7 @@ package compose
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/compose/v5/pkg/api"
|
"github.com/docker/compose/v5/pkg/api"
|
||||||
@@ -27,6 +28,8 @@ import (
|
|||||||
|
|
||||||
type startOptions struct {
|
type startOptions struct {
|
||||||
*ProjectOptions
|
*ProjectOptions
|
||||||
|
wait bool
|
||||||
|
waitTimeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
func startCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {
|
func startCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command {
|
||||||
@@ -41,6 +44,10 @@ func startCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *Back
|
|||||||
}),
|
}),
|
||||||
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
ValidArgsFunction: completeServiceNames(dockerCli, p),
|
||||||
}
|
}
|
||||||
|
flags := startCmd.Flags()
|
||||||
|
flags.BoolVar(&opts.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
|
||||||
|
flags.IntVar(&opts.waitTimeout, "wait-timeout", 0, "Maximum duration in seconds to wait for the project to be running|healthy")
|
||||||
|
|
||||||
return startCmd
|
return startCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +61,13 @@ func runStart(ctx context.Context, dockerCli command.Cli, backendOptions *Backen
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout := time.Duration(opts.waitTimeout) * time.Second
|
||||||
return backend.Start(ctx, name, api.StartOptions{
|
return backend.Start(ctx, name, api.StartOptions{
|
||||||
AttachTo: services,
|
AttachTo: services,
|
||||||
Project: project,
|
Project: project,
|
||||||
Services: services,
|
Services: services,
|
||||||
|
Wait: opts.wait,
|
||||||
|
WaitTimeout: timeout,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ Starts existing containers for a service
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|:------------|:-------|:--------|:--------------------------------|
|
|:-----------------|:-------|:--------|:---------------------------------------------------------------------------|
|
||||||
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
| `--dry-run` | `bool` | | Execute command in dry run mode |
|
||||||
|
| `--wait` | `bool` | | Wait for services to be running\|healthy. Implies detached mode. |
|
||||||
|
| `--wait-timeout` | `int` | `0` | Maximum duration in seconds to wait for the project to be running\|healthy |
|
||||||
|
|
||||||
|
|
||||||
<!---MARKER_GEN_END-->
|
<!---MARKER_GEN_END-->
|
||||||
|
|||||||
@@ -4,6 +4,28 @@ long: Starts existing containers for a service
|
|||||||
usage: docker compose start [SERVICE...]
|
usage: docker compose start [SERVICE...]
|
||||||
pname: docker compose
|
pname: docker compose
|
||||||
plink: docker_compose.yaml
|
plink: docker_compose.yaml
|
||||||
|
options:
|
||||||
|
- option: wait
|
||||||
|
value_type: bool
|
||||||
|
default_value: "false"
|
||||||
|
description: Wait for services to be running|healthy. Implies detached mode.
|
||||||
|
deprecated: false
|
||||||
|
hidden: false
|
||||||
|
experimental: false
|
||||||
|
experimentalcli: false
|
||||||
|
kubernetes: false
|
||||||
|
swarm: false
|
||||||
|
- option: wait-timeout
|
||||||
|
value_type: int
|
||||||
|
default_value: "0"
|
||||||
|
description: |
|
||||||
|
Maximum duration in seconds to wait for the project to be running|healthy
|
||||||
|
deprecated: false
|
||||||
|
hidden: false
|
||||||
|
experimental: false
|
||||||
|
experimentalcli: false
|
||||||
|
kubernetes: false
|
||||||
|
swarm: false
|
||||||
inherited_options:
|
inherited_options:
|
||||||
- option: dry-run
|
- option: dry-run
|
||||||
value_type: bool
|
value_type: bool
|
||||||
|
|||||||
Reference in New Issue
Block a user