我试图包括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?