Docker Compose's exec
command allocates a TTY by default, so you need to use the --no-TTY
flag if you want to pass, for example, a file containing SQL queries to a container running MariaDB.
$ docker compose exec --no-TTY my_db_service mysql -u root -p"my_root_password" my_database_name < temp.sql
Without --no-TTY
(or simply -T
), you get this error:
the input device is not a TTY
Final thoughts
Why docker exec
doesn't also do this is beyond me.
Also, to-do: read The TTY demystified.