Sometimes you want to execute command inside docker-compose service using input from the host machine. Instead of copy content from host machine to inside the container and run the command, you can use
docker-compose exec with stdin as an input.
You have backup
.sql file on your host machine and want to restore it into your Postgresql container. You can run:
cat /path/to/sql/file \ | docker-compose exec -T service_name \ psql -U username -d database_name
-T does the trick. By default,
exec command of docker-compose allocates pseudo-tty. With
-T, it will not -- which means it expects to do one-time command execution so that we can pipe the content of our SQL file in with