【问题标题】:Terminal progress bars not displaying in the Docker console.终端进度条未显示在 Docker 控制台中。
【发布时间】:2018-05-03 14:09:53
【问题描述】:

我试图包含一个 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。我尝试使用的其他包也存在此问题。

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

【问题讨论】:

    标签: node.js docker npm terminal


    【解决方案1】:

    你必须使用--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?

    【讨论】:

    • 非常感谢!像魅力一样工作。
    • 如果你有时间,还有一个问题,如果我在 docker-compose swarm(?) 中运行它,那么复制它的过程是什么。图像的 yml 节点内会是“tty: true”吗?
    • 是的,docker-compose.yml 上的等价物是 tty: true
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-13
    • 2020-10-02
    • 2015-06-18
    相关资源
    最近更新 更多