Skip to content

Commit d5e4f00

Browse files
committed
introduce --no-attach to ignore some service output
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 8b4ac37 commit d5e4f00

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

cmd/compose/up.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type upOptions struct {
4848
noPrefix bool
4949
attachDependencies bool
5050
attach []string
51+
noAttach []string
5152
timestamp bool
5253
wait bool
5354
}
@@ -128,6 +129,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob
128129
flags.BoolVar(&up.attachDependencies, "attach-dependencies", false, "Attach to dependent containers.")
129130
flags.BoolVar(&create.quietPull, "quiet-pull", false, "Pull without printing progress information.")
130131
flags.StringArrayVar(&up.attach, "attach", []string{}, "Attach to service output.")
132+
flags.StringArrayVar(&up.noAttach, "no-attach", []string{}, "Don't attach to specified service.")
131133
flags.BoolVar(&up.wait, "wait", false, "Wait for services to be running|healthy. Implies detached mode.")
132134

133135
return upCmd
@@ -185,6 +187,7 @@ func runUp(ctx context.Context, streams api.Streams, backend api.Service, create
185187
if len(attachTo) == 0 {
186188
attachTo = project.ServiceNames()
187189
}
190+
attachTo = utils.RemoveAll(attachTo, upOptions.noAttach)
188191

189192
create := api.CreateOptions{
190193
Services: services,

docs/reference/compose_up.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Create and start containers
1515
| `-d`, `--detach` | | | Detached mode: Run containers in the background |
1616
| `--exit-code-from` | `string` | | Return the exit code of the selected service container. Implies --abort-on-container-exit |
1717
| `--force-recreate` | | | Recreate containers even if their configuration and image haven't changed. |
18+
| `--no-attach` | `stringArray` | | Don't attach to specified service. |
1819
| `--no-build` | | | Don't build an image, even if it's missing. |
1920
| `--no-color` | | | Produce monochrome output. |
2021
| `--no-deps` | | | Don't start linked services. |
@@ -40,6 +41,9 @@ Builds, (re)creates, starts, and attaches to containers for a service.
4041
Unless they are already running, this command also starts any linked services.
4142

4243
The `docker compose up` command aggregates the output of each container (like `docker compose logs --follow` does).
44+
One can optionally select a subset of services to attach to using `--attach` flag, or exclude some services using
45+
`--no-attach` to prevent output to be flooded by some verbose services.
46+
4347
When the command exits, all containers are stopped. Running `docker compose up --detach` starts the containers in the
4448
background and leaves them running.
4549

docs/reference/docker_compose_up.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ long: |-
66
Unless they are already running, this command also starts any linked services.
77
88
The `docker compose up` command aggregates the output of each container (like `docker compose logs --follow` does).
9+
One can optionally select a subset of services to attach to using `--attach` flag, or exclude some services using
10+
`--no-attach` to prevent output to be flooded by some verbose services.
11+
912
When the command exits, all containers are stopped. Running `docker compose up --detach` starts the containers in the
1013
background and leaves them running.
1114
@@ -104,6 +107,16 @@ options:
104107
experimentalcli: false
105108
kubernetes: false
106109
swarm: false
110+
- option: no-attach
111+
value_type: stringArray
112+
default_value: '[]'
113+
description: Don't attach to specified service.
114+
deprecated: false
115+
hidden: false
116+
experimental: false
117+
experimentalcli: false
118+
kubernetes: false
119+
swarm: false
107120
- option: no-build
108121
value_type: bool
109122
default_value: "false"

pkg/utils/slices.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,14 @@ func Contains[T any](origin []T, element T) bool {
2828
}
2929
return false
3030
}
31+
32+
// RemoveAll removes all elements from origin slice
33+
func RemoveAll[T any](origin []T, elements []T) []T {
34+
var filtered []T
35+
for _, v := range origin {
36+
if !Contains(elements, v) {
37+
filtered = append(filtered, v)
38+
}
39+
}
40+
return filtered
41+
}

0 commit comments

Comments
 (0)