Skip to content

[BUG] config --variables doesn't honor --format flag #12808

Closed

Description

@alessio-perugini

Description

Providing the --variables and --format flag to the config command always results in printing in the human readable form.

A user would expect that when providing --format json the config --variables would produce a json output, but it currently doesn't

Steps To Reproduce

Using this oneliner:

printf '%s\n' \
"services:" \
"  test:" \
"    image: \${DOCKER_REGISTRY_BASE:-ubuntu/ubuntu:latest}" \
"    ports:" \
"      - \"\${BIND_ADDRESS:-127.0.0.1}:\${BIND_PORT:-8100}:8100\"" \
> /tmp/compose.yml &&
docker compose -f /tmp/compose.yml config --variables --format json

Output:

NAME                   REQUIRED            DEFAULT VALUE          ALTERNATE VALUE
DOCKER_REGISTRY_BASE   false               ubuntu/ubuntu:latest
BIND_PORT              false               8100
BIND_ADDRESS           false               127.0.0.1

Config example in case printf have some troubles working in your setup/terminal:

services:
  test:
    image: ${DOCKER_REGISTRY_BASE:-ubuntu/ubuntu:latest}
    ports:
      - "${BIND_ADDRESS:-127.0.0.1}:${BIND_PORT:-8100}:8100"

Compose Version

v2.35.1

Docker Environment

Client: Docker Engine - Community
 Version:    28.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.35.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 8
  Running: 5
  Paused: 0
  Stopped: 3
 Images: 40
 Server Version: 28.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.11.0-24-generic
 Operating System: Ubuntu 24.04.2 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 20
 Total Memory: 31.02GiB
 Name: ale
 ID: c4b213ee-6b17-445a-9dc6-6566795b9c0a
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

Expected output:

{
    "BIND_ADDRESS": {
        "Name": "BIND_ADDRESS",
        "DefaultValue": "127.0.0.1",
        "PresenceValue": "",
        "Required": false
    },
    "BIND_PORT": {
        "Name": "BIND_PORT",
        "DefaultValue": "8100",
        "PresenceValue": "",
        "Required": false
    },
    "DOCKER_REGISTRY_BASE": {
        "Name": "DOCKER_REGISTRY_BASE",
        "DefaultValue": "ubuntu/ubuntu:latest",
        "PresenceValue": "",
        "Required": false
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions