Skip to content

Commit f01bfc1

Browse files
committed
introduce --timeout on up
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent b19df5c commit f01bfc1

14 files changed

Lines changed: 96 additions & 72 deletions

cmd/compose/down.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func downCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4747
Use: "down [OPTIONS]",
4848
Short: "Stop and remove containers, networks",
4949
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
50-
opts.timeChanged = cmd.Flags().Changed("timeout")
50+
opts.timeChanged = cmd.Flags().Changed("waitTimeout")
5151
if opts.images != "" {
5252
if opts.images != "all" && opts.images != "local" {
5353
return fmt.Errorf("invalid value for --rmi: %q", opts.images)
@@ -64,7 +64,7 @@ func downCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
6464
flags := downCmd.Flags()
6565
removeOrphans := utils.StringToBool(os.Getenv("COMPOSE_REMOVE_ORPHANS"))
6666
flags.BoolVar(&opts.removeOrphans, "remove-orphans", removeOrphans, "Remove containers for services not defined in the Compose file.")
67-
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
67+
flags.IntVarP(&opts.timeout, "waitTimeout", "t", 10, "Specify a shutdown waitTimeout in seconds")
6868
flags.BoolVarP(&opts.volumes, "volumes", "v", false, "Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers.")
6969
flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`)
7070
flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName {

cmd/compose/restart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func restartCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
4343
ValidArgsFunction: completeServiceNames(p),
4444
}
4545
flags := restartCmd.Flags()
46-
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
46+
flags.IntVarP(&opts.timeout, "waitTimeout", "t", 10, "Specify a shutdown waitTimeout in seconds")
4747

4848
return restartCmd
4949
}

cmd/compose/stop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ func stopCommand(p *ProjectOptions, backend api.Service) *cobra.Command {
3939
Use: "stop [OPTIONS] [SERVICE...]",
4040
Short: "Stop services",
4141
PreRun: func(cmd *cobra.Command, args []string) {
42-
opts.timeChanged = cmd.Flags().Changed("timeout")
42+
opts.timeChanged = cmd.Flags().Changed("waitTimeout")
4343
},
4444
RunE: Adapt(func(ctx context.Context, args []string) error {
4545
return runStop(ctx, backend, opts, args)
4646
}),
4747
ValidArgsFunction: completeServiceNames(p),
4848
}
4949
flags := cmd.Flags()
50-
flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds")
50+
flags.IntVarP(&opts.timeout, "waitTimeout", "t", 10, "Specify a shutdown waitTimeout in seconds")
5151

5252
return cmd
5353
}

cmd/compose/up.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package compose
1919
import (
2020
"context"
2121
"fmt"
22+
"time"
2223

2324
"github.com/docker/compose/v2/cmd/formatter"
2425

@@ -48,6 +49,7 @@ type upOptions struct {
4849
noAttach []string
4950
timestamp bool
5051
wait bool
52+
waitTimeout int
5153
}
5254

5355
func (opts upOptions) apply(project *types.Project, services []string) error {
@@ -76,7 +78,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
7678
Short: "Create and start containers",
7779
PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error {
7880
create.pullChanged = cmd.Flags().Changed("pull")
79-
create.timeChanged = cmd.Flags().Changed("timeout")
81+
create.timeChanged = cmd.Flags().Changed("waitTimeout")
8082
return validateFlags(&up, &create)
8183
}),
8284
RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error {
@@ -102,7 +104,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
102104
flags.BoolVar(&up.noStart, "no-start", false, "Don't start the services after creating them.")
103105
flags.BoolVar(&up.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d")
104106
flags.StringVar(&up.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit")
105-
flags.IntVarP(&create.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.")
107+
flags.IntVarP(&create.timeout, "waitTimeout", "t", 10, "Use this waitTimeout in seconds for container shutdown when attached or when containers are already running.")
106108
flags.BoolVar(&up.timestamp, "timestamps", false, "Show timestamps.")
107109
flags.BoolVar(&up.noDeps, "no-deps", false, "Don't start linked services.")
108110
flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.")
@@ -112,6 +114,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
112114
flags.StringArrayVar(&up.attach, "attach", []string{}, "Attach to service output.")
113115
flags.StringArrayVar(&up.noAttach, "no-attach", []string{}, "Don't attach to specified service.")
114116
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
117+
flags.IntVar(&up.waitTimeout, "wait-timeout", 0, "timeout waiting for application to be running|healthy.")
115118

116119
return upCmd
117120
}
@@ -188,6 +191,8 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
188191
return backend.Create(ctx, project, create)
189192
}
190193

194+
timeout := time.Duration(upOptions.waitTimeout) * time.Second
195+
191196
return backend.Up(ctx, project, api.UpOptions{
192197
Create: create,
193198
Start: api.StartOptions{
@@ -197,6 +202,7 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
197202
ExitCodeFrom: upOptions.exitCodeFrom,
198203
CascadeStop: upOptions.cascadeStop,
199204
Wait: upOptions.wait,
205+
WaitTimeout: timeout,
200206
Services: services,
201207
},
202208
})

docs/reference/compose_down.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ Stop and remove containers, networks
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:-------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------|
10-
| `--remove-orphans` | | | Remove containers for services not defined in the Compose file. |
11-
| `--rmi` | `string` | | Remove images used by services. "local" remove only images that don't have a custom tag ("local"\|"all") |
12-
| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds |
13-
| `-v`, `--volumes` | | | Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers. |
8+
| Name | Type | Default | Description |
9+
|:----------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------|
10+
| `--remove-orphans` | | | Remove containers for services not defined in the Compose file. |
11+
| `--rmi` | `string` | | Remove images used by services. "local" remove only images that don't have a custom tag ("local"\|"all") |
12+
| `-v`, `--volumes` | | | Remove named volumes declared in the `volumes` section of the Compose file and anonymous volumes attached to containers. |
13+
| `-t`, `--waitTimeout` | `int` | `10` | Specify a shutdown waitTimeout in seconds |
1414

1515

1616
<!---MARKER_GEN_END-->

docs/reference/compose_restart.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Restart service containers
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:------------------|:------|:--------|:--------------------------------------|
10-
| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds |
8+
| Name | Type | Default | Description |
9+
|:----------------------|:------|:--------|:------------------------------------------|
10+
| `-t`, `--waitTimeout` | `int` | `10` | Specify a shutdown waitTimeout in seconds |
1111

1212

1313
<!---MARKER_GEN_END-->

docs/reference/compose_stop.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Stop services
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:------------------|:------|:--------|:--------------------------------------|
10-
| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds |
8+
| Name | Type | Default | Description |
9+
|:----------------------|:------|:--------|:------------------------------------------|
10+
| `-t`, `--waitTimeout` | `int` | `10` | Specify a shutdown waitTimeout in seconds |
1111

1212

1313
<!---MARKER_GEN_END-->

docs/reference/compose_up.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@ Create and start containers
55

66
### Options
77

8-
| Name | Type | Default | Description |
9-
|:-----------------------------|:--------------|:----------|:---------------------------------------------------------------------------------------------------------|
10-
| `--abort-on-container-exit` | | | Stops all containers if any container was stopped. Incompatible with -d |
11-
| `--always-recreate-deps` | | | Recreate dependent containers. Incompatible with --no-recreate. |
12-
| `--attach` | `stringArray` | | Attach to service output. |
13-
| `--attach-dependencies` | | | Attach to dependent containers. |
14-
| `--build` | | | Build images before starting containers. |
15-
| `-d`, `--detach` | | | Detached mode: Run containers in the background |
16-
| `--exit-code-from` | `string` | | Return the exit code of the selected service container. Implies --abort-on-container-exit |
17-
| `--force-recreate` | | | Recreate containers even if their configuration and image haven't changed. |
18-
| `--no-attach` | `stringArray` | | Don't attach to specified service. |
19-
| `--no-build` | | | Don't build an image, even if it's missing. |
20-
| `--no-color` | | | Produce monochrome output. |
21-
| `--no-deps` | | | Don't start linked services. |
22-
| `--no-log-prefix` | | | Don't print prefix in logs. |
23-
| `--no-recreate` | | | If containers already exist, don't recreate them. Incompatible with --force-recreate. |
24-
| `--no-start` | | | Don't start the services after creating them. |
25-
| `--pull` | `string` | `missing` | Pull image before running ("always"\|"missing"\|"never") |
26-
| `--quiet-pull` | | | Pull without printing progress information. |
27-
| `--remove-orphans` | | | Remove containers for services not defined in the Compose file. |
28-
| `-V`, `--renew-anon-volumes` | | | Recreate anonymous volumes instead of retrieving data from the previous containers. |
29-
| `--scale` | `stringArray` | | Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present. |
30-
| `-t`, `--timeout` | `int` | `10` | Use this timeout in seconds for container shutdown when attached or when containers are already running. |
31-
| `--timestamps` | | | Show timestamps. |
32-
| `--wait` | | | Wait for services to be running\|healthy. Implies detached mode. |
8+
| Name | Type | Default | Description |
9+
|:-----------------------------|:--------------|:----------|:-------------------------------------------------------------------------------------------------------------|
10+
| `--abort-on-container-exit` | | | Stops all containers if any container was stopped. Incompatible with -d |
11+
| `--always-recreate-deps` | | | Recreate dependent containers. Incompatible with --no-recreate. |
12+
| `--attach` | `stringArray` | | Attach to service output. |
13+
| `--attach-dependencies` | | | Attach to dependent containers. |
14+
| `--build` | | | Build images before starting containers. |
15+
| `-d`, `--detach` | | | Detached mode: Run containers in the background |
16+
| `--exit-code-from` | `string` | | Return the exit code of the selected service container. Implies --abort-on-container-exit |
17+
| `--force-recreate` | | | Recreate containers even if their configuration and image haven't changed. |
18+
| `--no-attach` | `stringArray` | | Don't attach to specified service. |
19+
| `--no-build` | | | Don't build an image, even if it's missing. |
20+
| `--no-color` | | | Produce monochrome output. |
21+
| `--no-deps` | | | Don't start linked services. |
22+
| `--no-log-prefix` | | | Don't print prefix in logs. |
23+
| `--no-recreate` | | | If containers already exist, don't recreate them. Incompatible with --force-recreate. |
24+
| `--no-start` | | | Don't start the services after creating them. |
25+
| `--pull` | `string` | `missing` | Pull image before running ("always"\|"missing"\|"never") |
26+
| `--quiet-pull` | | | Pull without printing progress information. |
27+
| `--remove-orphans` | | | Remove containers for services not defined in the Compose file. |
28+
| `-V`, `--renew-anon-volumes` | | | Recreate anonymous volumes instead of retrieving data from the previous containers. |
29+
| `--scale` | `stringArray` | | Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present. |
30+
| `--timestamps` | | | Show timestamps. |
31+
| `--wait` | | | Wait for services to be running\|healthy. Implies detached mode. |
32+
| `--wait-timeout` | `int` | `0` | timeout waiting for application to be running\|healthy. |
33+
| `-t`, `--waitTimeout` | `int` | `10` | Use this waitTimeout in seconds for container shutdown when attached or when containers are already running. |
3334

3435

3536
<!---MARKER_GEN_END-->

docs/reference/docker_compose_down.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@ options:
3838
experimentalcli: false
3939
kubernetes: false
4040
swarm: false
41-
- option: timeout
42-
shorthand: t
43-
value_type: int
44-
default_value: "10"
45-
description: Specify a shutdown timeout in seconds
46-
deprecated: false
47-
hidden: false
48-
experimental: false
49-
experimentalcli: false
50-
kubernetes: false
51-
swarm: false
5241
- option: volumes
5342
shorthand: v
5443
value_type: bool
@@ -61,6 +50,17 @@ options:
6150
experimentalcli: false
6251
kubernetes: false
6352
swarm: false
53+
- option: waitTimeout
54+
shorthand: t
55+
value_type: int
56+
default_value: "10"
57+
description: Specify a shutdown waitTimeout in seconds
58+
deprecated: false
59+
hidden: false
60+
experimental: false
61+
experimentalcli: false
62+
kubernetes: false
63+
swarm: false
6464
deprecated: false
6565
experimental: false
6666
experimentalcli: false

docs/reference/docker_compose_restart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ usage: docker compose restart [OPTIONS] [SERVICE...]
1515
pname: docker compose
1616
plink: docker_compose.yaml
1717
options:
18-
- option: timeout
18+
- option: waitTimeout
1919
shorthand: t
2020
value_type: int
2121
default_value: "10"
22-
description: Specify a shutdown timeout in seconds
22+
description: Specify a shutdown waitTimeout in seconds
2323
deprecated: false
2424
hidden: false
2525
experimental: false

0 commit comments

Comments
 (0)