liujin834
V2EX  ›  Node.js

Nodejs 执行 Docker run 的 stdout 问题

  •  
  •   liujin834 · May 6, 2017 · 3345 views
    This topic created in 3339 days ago, the information mentioned may be changed or developed.

    请教各位大神 nodejs 调用 docker run 命令的问题

    由于执行时间比较长,我想把执行中的输出抓出来

    代码是这样的

    var p = spawn('docker', [
            'run',
            '-i',
            '-a', 'stdout',
            '-a', 'stderr',
            '--rm',
            '-v', imagesPath + ':/code/images',
            'westdc_dem'
        ]);
    
    p.stdout.on('data', function (data){
        console.log(data.toString());
    });
    

    它现在不能按我的预期一行一行打印,而是整个执行完才打印,怎么才能让它一行一行输出呢?

    4 replies    2017-05-07 21:42:36 +08:00
    pasturn
        1
    pasturn  
       May 7, 2017
    var p = spawn('docker', [
    'run',
    '-i',
    '-a', 'stdout',
    '-a', 'stderr',
    '--rm',
    '-v', imagesPath + ':/code/images',
    'westdc_dem'
    ],{ stdio: 'inherit'});
    cloverstd
        2
    cloverstd  
       May 7, 2017
    为啥不用 docker api
    liujin834
        3
    liujin834  
    OP
       May 7, 2017
    @cloverstd 最终用 docker api 解决了,谢谢
    liujin834
        4
    liujin834  
    OP
       May 7, 2017
    @pasturn 谢谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1536 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 16:32 · PVG 00:32 · LAX 09:32 · JFK 12:32
    ♥ Do have faith in what you're doing.