Skip to content

[BUG] docker compose config --output results an empty file because of the not flushed bufio writer #10121

Closed
@rimelek

Description

@rimelek

Description

The "config" (or convert) subcommand of Docker Compose should write the output to a file instead of the standard output when I use the --output output.yml parameter. It creates the file but doesnt write anything into it. The result is an empty file.

Steps To Reproduce

  1. Create any compose file
  2. run docker compose config --output output.yml
  3. Test the output: cat output.yml

Compose Version

The original: `Docker Compose version v2.13.0`
The custom build for testing from the Compose v2 repo: `Docker Compose version v2.14.2-20-gfd353ffa.m`

Docker Environment

Client:
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.13.0)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.16)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.22.0)

Server:
 Containers: 24
  Running: 20
  Paused: 0
  Stopped: 4
 Images: 68
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 3
 Total Memory: 3.841GiB
 Name: docker-desktop
 ID: GHHA:R5X5:PFCQ:6VI6:SDLO:JQNB:JKVS:BGVL:7PF3:W2DN:5XHT:UDYB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

I checked the sourcecode and find this part in the runConvert method.

out = bufio.NewWriter(file)

The type of out is io.Writer which is good for the default destination (standard output) but when I set the --output option, it saaves a bufio.Writer in out. I found out that bufio.Writer should be flushed, so I tested the theory and it worked, but then the standard output could not be the default value of out because of the different types. So I guess I could have create a new variable in the "if" block, write the content like this

bufout.Write(content)
bufout.Flush()

and return, but I don't know if this is the best solution so or I could flush the writer some other way. If you think it would be the right way, I am happy to send a pull request.

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