我试图包含一个 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();
这是我的 docker 文件:
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。我尝试使用的其他包也存在此问题。
如能提供与预期结果不同的原因的任何信息,我们将不胜感激。谢谢。
最佳答案
您必须使用 --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?
关于node.js - 终端进度条未显示在 Docker 控制台中。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50157129/