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