dockerode icon indicating copy to clipboard operation
dockerode copied to clipboard

containerAttach is sending parameter as POST JSON payload while it shouldn't

Open benoitf opened this issue 2 years ago • 4 comments

Hello,

When trying to use dockerode with podman engine, I noticed that I received echo of queries when using attach on a container.

Reading https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerAttach we can see that parameters like stdin, stdout, stream, etc are all query parameters like /v1.43/containers/{id}/attach?stdin=...&stdout=... but dockerode also send the options as a JSON payload {"stream": true, "stdin":true, "stdout":true}

the API don't mention a payload so for attach API, dockerode shouldn't send any body on the REST API call.

benoitf avatar Sep 12 '23 07:09 benoitf

That can be a real problem when trying to work with images that expect some meaningful input in stdin.

We've implemented workaround using proxy object:

container.modem = new Proxy(container.modem, {
      get(target, prop) {
        const origMethod = target[prop];
        if (prop === "dial") {
            return function (...args) {
              if (args[0].path.endsWith("/attach?")) {
                // make request body empty
                args[0].file = new Buffer("")
              }
              return origMethod.apply(target, args)
            }
        } else {
          return origMethod
        }
      }
    })

absorbb avatar May 17 '24 18:05 absorbb