From 66524e77287e10b7b4bf82ca39b8cfffd84c526f Mon Sep 17 00:00:00 2001 From: MohammadHasan Akbari Date: Sun, 6 Jul 2025 15:41:55 +0000 Subject: [PATCH] feat: add --networks flag to config command Signed-off-by: MohammadHasan Akbari --- cmd/compose/config.go | 16 ++++++++++++++++ docs/reference/compose_config.md | 1 + docs/reference/docker_compose_config.yaml | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/cmd/compose/config.go b/cmd/compose/config.go index 3cb969108..354978295 100644 --- a/cmd/compose/config.go +++ b/cmd/compose/config.go @@ -50,6 +50,7 @@ type configOptions struct { noResolveEnv bool services bool volumes bool + networks bool profiles bool images bool hash string @@ -111,6 +112,9 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command { if opts.volumes { return runVolumes(ctx, dockerCli, opts) } + if opts.networks { + return runNetworks(ctx, dockerCli, opts) + } if opts.hash != "" { return runHash(ctx, dockerCli, opts) } @@ -147,6 +151,7 @@ func configCommand(p *ProjectOptions, dockerCli command.Cli) *cobra.Command { flags.BoolVar(&opts.services, "services", false, "Print the service names, one per line.") flags.BoolVar(&opts.volumes, "volumes", false, "Print the volume names, one per line.") + flags.BoolVar(&opts.networks, "networks", false, "Print the network names, one per line.") flags.BoolVar(&opts.profiles, "profiles", false, "Print the profile names, one per line.") flags.BoolVar(&opts.images, "images", false, "Print the image names, one per line.") flags.StringVar(&opts.hash, "hash", "", "Print the service config hash, one per line.") @@ -367,6 +372,17 @@ func runVolumes(ctx context.Context, dockerCli command.Cli, opts configOptions) return nil } +func runNetworks(ctx context.Context, dockerCli command.Cli, opts configOptions) error { + project, err := opts.ToProject(ctx, dockerCli, nil, cli.WithoutEnvironmentResolution) + if err != nil { + return err + } + for n := range project.Networks { + _, _ = fmt.Fprintln(dockerCli.Out(), n) + } + return nil +} + func runHash(ctx context.Context, dockerCli command.Cli, opts configOptions) error { var services []string if opts.hash != "*" { diff --git a/docs/reference/compose_config.md b/docs/reference/compose_config.md index 3ec2d4864..854eafe21 100644 --- a/docs/reference/compose_config.md +++ b/docs/reference/compose_config.md @@ -15,6 +15,7 @@ the canonical format. | `--hash` | `string` | | Print the service config hash, one per line. | | `--images` | `bool` | | Print the image names, one per line. | | `--lock-image-digests` | `bool` | | Produces an override file with image digests | +| `--networks` | `bool` | | Print the network names, one per line. | | `--no-consistency` | `bool` | | Don't check model consistency - warning: may produce invalid Compose output | | `--no-env-resolution` | `bool` | | Don't resolve service env files | | `--no-interpolate` | `bool` | | Don't interpolate environment variables | diff --git a/docs/reference/docker_compose_config.yaml b/docs/reference/docker_compose_config.yaml index 080fe6748..b95c58c27 100644 --- a/docs/reference/docker_compose_config.yaml +++ b/docs/reference/docker_compose_config.yaml @@ -56,6 +56,16 @@ options: experimentalcli: false kubernetes: false swarm: false + - option: networks + value_type: bool + default_value: "false" + description: Print the network names, one per line. + deprecated: false + hidden: false + experimental: false + experimentalcli: false + kubernetes: false + swarm: false - option: no-consistency value_type: bool default_value: "false"