3

Im trying to include one of npm's terminal progress bars to better visualize how a long process is progressing. When I run it from the standard "node index.js" it goes off without a hitch, but when running from a simple docker image, nothing is posted to the terminal. My index.js reads as such:

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();

And this is my docker file:

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" ]

The terminal displays nothing from these packages but does display the normal console.logs.This problem exists for the other package I tried to use as well.

Any information on why this is having a different than the expected result would be greatly appreciated. Thanks.

Connor Campbell
  • 145
  • 1
  • 2
  • 7

1 Answers1

4

You have to run docker, with --tty , -t flag, which will allocate a pseudo-TTY

docker run -t --rm test

You can check the following questions for a more detailed explanation on that flag:

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?

Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98