How to use `docker compose exec` with both grep and ANSI color?

227 Views Asked by At

I'm only casually familiar with Docker, and how TTYs work in Linux. At work, I use commands like docker compose up to start the development stack (Postgres + Django), and docker compose exec web python manage.py ... to run Django commands during development.

Conflicting problems:

  1. I can't pipe in input or grep output without adding -T. I don't know why, I just know it works with it, and not without it.

    • I populate the DB with docker compose exec -T db psql -U username myproj < snapshot.sql because without the -T the input doesn't make it to psql.
    • I also add -T when I have to grep the output, like:
      docker compose exec web python manage.py showmigrations | grep '[ ]'.
  2. However, when I use -T, it screws up ANSI coloring and formatting.

    • Without -T: enter image description here
    • With -T: enter image description here

Question: What's the correct method? How do I properly connect STDIN & STDOUT without messing up color & formatting?

0

There are 0 best solutions below