diff --git a/cmd/compose/config.go b/cmd/compose/config.go index 8631956ce..b06e620b1 100644 --- a/cmd/compose/config.go +++ b/cmd/compose/config.go @@ -136,21 +136,34 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command { } func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error { - model, err := opts.ToModel(ctx, dockerCli, services) - if err != nil { - return err - } - - if opts.resolveImageDigests { - err = resolveImageDigests(ctx, dockerCli, model) + var content []byte + if opts.noInterpolate { + // we can't use ToProject, so the model we render here is only partially resolved + model, err := opts.ToModel(ctx, dockerCli, services) if err != nil { return err } - } - content, err := formatModel(model, opts.Format) - if err != nil { - return err + if opts.resolveImageDigests { + err = resolveImageDigests(ctx, dockerCli, model) + if err != nil { + return err + } + } + + content, err = formatModel(model, opts.Format) + if err != nil { + return err + } + } else { + project, err := opts.ToProject(ctx, dockerCli, services) + if err != nil { + return err + } + content, err = project.MarshalYAML() + if err != nil { + return err + } } if !opts.noInterpolate { @@ -164,7 +177,7 @@ func runConfig(ctx context.Context, dockerCli command.Cli, opts configOptions, s if opts.Output != "" && len(content) > 0 { return os.WriteFile(opts.Output, content, 0o666) } - _, err = fmt.Fprint(dockerCli.Out(), string(content)) + _, err := fmt.Fprint(dockerCli.Out(), string(content)) return err } diff --git a/pkg/e2e/compose_test.go b/pkg/e2e/compose_test.go index 28d8b0eb7..75d546f73 100644 --- a/pkg/e2e/compose_test.go +++ b/pkg/e2e/compose_test.go @@ -245,9 +245,6 @@ func TestConfig(t *testing.T) { t.Run("up", func(t *testing.T) { res := c.RunDockerComposeCmd(t, "-f", "./fixtures/simple-build-test/compose.yaml", "-p", projectName, "convert") res.Assert(t, icmd.Expected{Out: fmt.Sprintf(`name: %s -networks: - default: - name: compose-e2e-convert_default services: nginx: build: @@ -255,6 +252,9 @@ services: dockerfile: Dockerfile networks: default: null +networks: + default: + name: compose-e2e-convert_default `, projectName, filepath.Join(wd, "fixtures", "simple-build-test", "nginx-build")), ExitCode: 0}) }) }