diff --git a/cmd/compose/run.go b/cmd/compose/run.go index ef7e127d..39f47609 100644 --- a/cmd/compose/run.go +++ b/cmd/compose/run.go @@ -262,7 +262,9 @@ func startDependencies(ctx context.Context, backend api.Service, project types.P } if len(dependencies) > 0 { - return backend.Start(ctx, project.Name, api.StartOptions{}) + return backend.Start(ctx, project.Name, api.StartOptions{ + Project: &project, + }) } return nil } diff --git a/pkg/e2e/compose_run_test.go b/pkg/e2e/compose_run_test.go index fdd5803d..00dcb8f0 100644 --- a/pkg/e2e/compose_run_test.go +++ b/pkg/e2e/compose_run_test.go @@ -117,4 +117,16 @@ func TestLocalComposeRun(t *testing.T) { res := c.RunDockerCmd("ps", "--all") assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout()) }) + + t.Run("run starts only container and dependencies", func(t *testing.T) { + // ensure that even if another service is up run does not start it: https://github.com/docker/compose/issues/9459 + res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "up", "service_b") + res.Assert(t, icmd.Success) + + res = c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "run", "service_a") + assert.Assert(t, strings.Contains(res.Combined(), "shared_dep"), res.Combined()) + assert.Assert(t, !strings.Contains(res.Combined(), "service_b"), res.Combined()) + + c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans") + }) } diff --git a/pkg/e2e/fixtures/run-test/deps.yaml b/pkg/e2e/fixtures/run-test/deps.yaml new file mode 100644 index 00000000..4b6c5fca --- /dev/null +++ b/pkg/e2e/fixtures/run-test/deps.yaml @@ -0,0 +1,14 @@ +version: "3.6" +services: + service_a: + image: bash + command: echo "a" + depends_on: + - shared_dep + service_b: + image: bash + command: echo "b" + depends_on: + - shared_dep + shared_dep: + image: bash \ No newline at end of file