Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
82 views
in Technique[技术] by (71.8m points)

node.js - Why can't I send input to my Docker stream that is attached?

I'm creating an application that uses Docker with Dockerode and I want to attach it to the container and sending input and get output back and forth and this is my current code but for some reason, I can't send input. I sent it but I get nothing back as output, I don't know if I am doing this correctly.

      var containerID = message.d.id

      var container = await docker.getContainer(containerID)

      if (!activeContainers[containerID]) {
        var container = await docker.getContainer(containerID)
        var idk = new stream.PassThrough()

        idk.resume()
        idk.on('data', (data) => {
          ws.send(JSON.stringify({
            op: 10,
            d: data.toString(),
            machineID: message.d.machineID
          }))
        })

        var s = await container.attach({ stream: true, stdin: true, stdout: true, stderr: true })

        s.pipe(idk)


        s.on('end', () => {
          delete activeContainers[inspect.Id]
        })

        activeContainers[inspect.Id] = {
          attach: s,
          stdin: process.stdin
        }

        process.stdin.resume()
        process.stdin.setEncoding('utf8')
        process.stdin.setRawMode(true)
        process.stdin.pipe(s)

        await container.start()

        activeContainers[containerID].stdin.write(message.d.exec + '
')
        return
      }

      activeContainers[containerID].stdin.write(message.d.exec + '
')
question from:https://stackoverflow.com/questions/65943780/why-cant-i-send-input-to-my-docker-stream-that-is-attached

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...