Skip to content

Commit 80b7a8d

Browse files
laurazardndeloof
authored andcommitted
Only start direct dependencies of service on compose run ...
Signed-off-by: Laura Brehm <[email protected]>
1 parent 8862f95 commit 80b7a8d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

cmd/compose/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ func startDependencies(ctx context.Context, backend api.Service, project types.P
262262
}
263263

264264
if len(dependencies) > 0 {
265-
return backend.Start(ctx, project.Name, api.StartOptions{})
265+
return backend.Start(ctx, project.Name, api.StartOptions{
266+
Project: &project,
267+
})
266268
}
267269
return nil
268270
}

pkg/e2e/compose_run_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,16 @@ func TestLocalComposeRun(t *testing.T) {
117117
res := c.RunDockerCmd("ps", "--all")
118118
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
119119
})
120+
121+
t.Run("run starts only container and dependencies", func(t *testing.T) {
122+
// ensure that even if another service is up run does not start it: https://github.com/docker/compose/issues/9459
123+
res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "up", "service_b")
124+
res.Assert(t, icmd.Success)
125+
126+
res = c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "run", "service_a")
127+
assert.Assert(t, strings.Contains(res.Combined(), "shared_dep"), res.Combined())
128+
assert.Assert(t, !strings.Contains(res.Combined(), "service_b"), res.Combined())
129+
130+
c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
131+
})
120132
}

pkg/e2e/fixtures/run-test/deps.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3.6"
2+
services:
3+
service_a:
4+
image: bash
5+
command: echo "a"
6+
depends_on:
7+
- shared_dep
8+
service_b:
9+
image: bash
10+
command: echo "b"
11+
depends_on:
12+
- shared_dep
13+
shared_dep:
14+
image: bash

0 commit comments

Comments
 (0)