3

I'm trying to use the pv command in my Dockerfile but nothing is displayed on screen when I call the building process.

I made a very simple version of my Dockerfile :

FROM debian:jessie RUN apt-get update && apt-get install -y pv RUN echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit." | pv -L 5 -s56 > /dev/null 

If I run the command in a simple terminal i've got this output :

35 B 0:00:07 [5.35 B/s] [================================================================> ] 62% ETA 0:00:04` 

But when I run my docker build like this docker build -t foo . I only got this :

Sending build context to Docker daemon 2.048 kB Step 1 : FROM debian:jessie ---> 040bf8e08425 Step 2 : RUN apt-get update && apt-get install -y pv ---> Using cache ---> 155e9ebf615f Step 3 : RUN echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit." | pv -L 5 -s56 > /dev/null ---> Running in 3afdb7b5822c ---> 6fcf83d0cd02 Removing intermediate container 3afdb7b5822c Successfully built 6fcf83d0cd02 

Is there a way to have this pv command to work ?

Thank you !

5
  • 1
    Your pv happens during docker build and as you have no CMD nor ENTRYPOINT in your Dockerfile, nothing happens, this is normal Commented Mar 21, 2016 at 17:52
  • but the echo is well done if I put out the > /dev/null part. So why not the output of pv ? And the CMD and ENTRYPOINT are for the run process not for the build right ? Actually I'm lauching the build command not the run one Commented Mar 22, 2016 at 7:24
  • Commands that runs during docker build have no access to terminal so pv cannot work. Commented Mar 22, 2016 at 9:03
  • Thanks for answers, but i really don't undersand. What is an "access to terminal" ? the pv command works because the echo is slowed by the -L 5 option. And the output of echo command works too. The only output that don't work is the one of pv. What is the diffrence between the way pv output something and the way echo does ? Commented Mar 22, 2016 at 10:00
  • @user1918998 Did you ever find out why the pv output isn't visible whereas the echo output is? Commented Apr 14, 2016 at 11:00

1 Answer 1

7

Use pv -f or pv --force and it will work the way you expect it to. Quoting the man page for pv:

 -f, --force Force output. Normally, pv will not output any visual display if standard error is no a terminal. This option forces it to do so. 

I don't know if this was an option three+ years ago when this question was posed, but it works now.

With this in my Dockerfile like so:

RUN echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit." | pv -f -L 5 -s57 > /dev/null 

I get the following as an example output along the way:

Step 3/3 : RUN echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit." | pv -f -L 5 -s57 > /dev/null ---> Running in 57c657f93610 25.0 B 0:00:05 [5.21 B/s] [==============> ] 44% ETA 0:00:06 

... also, to get the "100%" right, you either need to run pv -s57 or echo -n to suppress the newline.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.