终端进度条未显示在Docker控制台中。

时间:2018-05-03 14:09:54

标签: node.js docker npm terminal

我试图包含一个npm的终端进度条,以更好地可视化长进程的进展情况。当我从标准的“node index.js”运行它时,它会毫无障碍地运行,但是当从简单的docker镜像运行时,没有任何内容发送到终端。我的index.js读起来是这样的:

const _cliProgress = require('cli-progress');

// create a new progress bar instance and use shades_classic theme
const bar1 = new _cliProgress.Bar({}, _cliProgress.Presets.shades_classic);

// start the progress bar with a total value of 200 and start value of 0
bar1.start(200, 0);

// update the current value in your application..
bar1.update(100);

// stop the progress bar
bar1.stop();

这是我的泊坞文件:

FROM node:latest

#create work directory
RUN mkdir -p /src

#establish the app folder as the work directory
WORKDIR /src

COPY package.json /src

COPY package-lock.json /src

RUN npm i

COPY . /src

CMD [ "node", "index.js" ]

终端没有显示这些包中的任何内容,但显示正常的console.logs.This问题存在于我试图使用的其他包中。

有关为何与预期结果不同的任何信息将不胜感激。感谢。

1 个答案:

答案 0 :(得分:2)

你必须使用--tty , -t标志运行docker,它将分配一个伪TTY

docker run -t --rm test

您可以查看以下问题,以获得有关该标志的更详细说明:

Confused about Docker -t option to Allocate a pseudo-TTY

What does it mean to attach a tty/std-in-out to dockers or lxc?