dockerode icon indicating copy to clipboard operation
dockerode copied to clipboard

Remove control characters from UNIX Domain Socket

Open bllmo opened this issue 2 years ago • 0 comments

Hello, i have a problem with docker exec command output, when i try to run:

// modem.js

var Docker = require("dockerode");
const path = require("path");

var docker = new Docker({ socketPath: "/var/run/docker.sock" });

docker.createContainer(
  {
    Tty: false,
    Image: "ubuntu",
    Cmd: ["/bin/bash"],
    OpenStdin: true,
    Volumes: {
      "/tmp": {},
    },
    HostConfig: {
      Binds: [`${path.resolve("./tmp")}:/tmp`],
    },
  },
  function (err, container) {
    container.start(function (err) {
      container.exec(
        { Cmd: ["cat", "./tmp/schema.json"], AttachStdin: true, AttachStdout: true },
        function (err, exec) {
          exec.start({ hijack: true, stdin: true }, function (err, stream) {
            let chunks = [];

            stream.on("data", (chunk) => { 
              chunks.push(chunk.toString("utf-8"))
            });
      
            stream.on("error", (err) => reject(err));
            stream.on("end", () => {
               // console.log(JSON.parse(chunks.join(""))) parsing error
                console.log(chunks.join(""))
            });
          });
        }
      );
    });
  }
);

Where schema.json is a large file (21MB)

but when i parse with json parse the result of this promise i receive this control characters:

175333952-98ed5cbc-259a-4b9d-a8fd-438dab81868a

is possible to remove this control characters from the chunks?

i run node modem.js > logs.json for replicate the problem

bllmo avatar Jun 24 '22 12:06 bllmo