wget in docker prints thousands of lines to show progress instead of a single line progress bar

Viewed 1241

When I wget a file, e.g. from GitHub, it shows a nice one-line progress bar like that:

wget -N http://db.sqlite.zip
db.sqlite.zip   28%[====>                       ]  68.79M   370KB/s    eta 5m 53s 

But I run the wget command exactly the same way when starting up a container, as a bash script to get some data, it prints thousands of lines, apparently for each 50K bits which are downloaded:

app_1  |      0K .......... .......... .......... ..........  0%  212K 19m12s
app_1  |     50K .......... .......... .......... ..........  0%  426K 14m22s
app_1  |    100K .......... .......... .......... ..........  0% 38.4M 9m37s
app_1  |    150K .......... .......... .......... ..........  0%  430K 9m35s
app_1  |    200K .......... .......... .......... ..........  0% 33.9M 7m41s
...

+ many... many more of these lines (it actually fills the stdout buffer and I don't want to).

How could I get the same behaviour, e.g. displaying a one-line progress bar, than on my host machine? If possible of course. Otherwise I simply -q it and that's over.

2 Answers

During build docker does not allocate a tty. This will make wget fall back to the dot display method for progress bars.

Sadly, there is no straightforward solution to your problem. Following a few suggestions:

  • Force the bar method:
wget \
  --no-verbose --show-progress \
  --progress=bar:force:noscroll \
  url

NOTE: this will most likely still produce quite a few lines of output.

  • Make the dot method print lines less often:
wget \
  --no-verbose --show-progress \
  --progress=dot:mega \
  url
  • Write some custom scripts which transform the output of wget to what you want.

This command needs to download the specified new container image. You have noticed that a lot of “layers” were downloaded. This is because your container image is build on top of another one, so you need to download that also, and probably that image is build on top of another etc. and that's why you are being displayed all those lines of download. That's how docker architecture works. enter image description here

So coming back to your initial question, you can't instruct wget to get the downloads sequentially for docker. But you can pipe the command to get only the first line on console output. Of course the others still exist, but you won't see them.

wget image_name | head -n 1
Related