Repository navigation
Doesn't work with docker-compose #771
Description
Activity
Image:
FROM python:3.6Which is running 3.6.6
Have tried it on two different computers and in both MacOS Terminal and VS Code Terminal.
- addedp2-bug-warning ⚠Visual output badVisual output badto-fix ⌛In progressIn progress
on Jul 7, 2019 The problem is not with Docker itself, but Docker Compose.
To reproduce the problem, you need to first write a
docker-compose.yamlfile for your Docker service. Then bring up everything up by runningdocker-compose up -dand then following the logs by runningdocker-compose logs -f(or just run without -d, it will run in foreground I believe). If you follow these steps, you will find that the tqdm log line will not get outputted until a newline has been fed to stdout of that particular container after the loop has finished.The problem is not present if you just use Docker itself with the
--ttyflag.Reacted by Aneesh Vartakavi, iMad, AG-LC, Eric, Stelios M., tastyz4z4, Kevin Zhang and Edgar GraciaReacted by Justin Pierce, Stelios M. and tastyz4z4thanks @sepbot - is this something that's been reported on the docker-compose repo?
- addedinvalid ⛔Not-an-issue or upstream (not-our-issue)Not-an-issue or upstream (not-our-issue)and removedp2-bug-warning ⚠Visual output badVisual output badto-fix ⌛In progressIn progress
on Jul 12, 2019 I'm running into the same issue, are there any known workarounds or fixes for getting tqdm to work in docker compose?
Reacted by Shahid Yar, Matthew Timms and Botty Dimanov- changed the title
[-]Doesn't work in Docker? [/-][+]Doesn't work with docker-compose[/+]on Sep 17, 2019 - addedhelp wanted 🙏We need you (discussion or implementation)We need you (discussion or implementation)
on Sep 17, 2019 Did anyone manage to get the progress bar in the docker-compose. Any workaround?
Reacted by Botty DimanovUse
docker-compose runinstead ofdocker-compose upandtty: truein your service configReacted by Fadi Younes, Liam Wood Roberts and willianmariaReacted by 寒山, Filip Sondej, Philipp Dörfler, Ebi Soroush, willianmaria, Dmitrii Evseev, Charles Gallay and Vlad CruduUse
docker-compose runinstead ofdocker-compose upandtty: truein your service configJust using
docker-compose runin my compose yml worked for me (tty: truemade no noticeable difference).Reacted by Fadi YounesUse
docker-compose runinstead ofdocker-compose upandtty: truein your service configJust using
docker-compose runin my compose yml worked for me (tty: truemade no noticeable difference).You're right,
docker-compose runallocates a TTY by default. Didn't know that at the time.- addedquestion/docs ‽Documentation clarification candidateDocumentation clarification candidateto-merge ↰ImminentImminentand removedhelp wanted 🙏We need you (discussion or implementation)We need you (discussion or implementation)
on Jul 7, 2020 - added 2 commits that reference this issue
on Jul 19, 2020 This workaround works fine too. For those who want to keep using docker compose up
it = tqdm(total=len(arr)) for e in arr: it.update(1) print(it)
This command can help if you are running in detach mode:
docker compose up -d docker attach --sig-proxy=false [container-name]
https://docs.docker.com/reference/cli/docker/container/attach/
You must set
tty: trueto the service.Reacted by Guillaume, Kisoo Kim, Teradater, Rizky Adi and Ousama EsbelReacted by StoufaThis discussion/thread was a true saver! I would never have guessed that its a docker-compose issue related to some missing newline. Although the issue is closed, I'd still like to contribute a little bit back with my workaround.
from tqdm import tqdm tqdm_is_server = True # somehow decide (e.g. check for tty) tqdm_disable = False # server has no tty, but we use tqdm anyway class ServerTqdm(tqdm): def update(self, n=1): result = super().update(n) if result and tqdm_is_server: print(f"{self}\n") return result def display(self, msg=None, pos=None): if not tqdm_is_server: return super().display(msg, pos) return True for foo in ServerTqdm(range(0, 10), disable=tqdm_disable): print(foo)
Based on Ghost---Shadow workaround and sepbot insight!
Thank you two!Reacted by YuchiSu and Souradeep Nanda
Then in terminal I see nothing until the loop has finished, and it just prints:
debug: 100% 50/50 [00:05<00:00, 9.81it/s]My docker compose file has
tty: trueandos.isatty(sys.stdout.fileno())returns true