Output of script command is written after the exit command, instead of ongoing basis

host# docker run -dit --tty ubuntu
host# docker exec -it container-id /bin/bash
container# script terminal.out
container# ls
container# date
container# cat terminal.out (it’s empty, een thoug it should have output of 2 previous commands)
contaienr# exit
container# cat terminal.out (it gives all the output now)

Normally, script command writes to terminal.out file in every few seconds instead of writing all at once after exit command. (any solution to get the normal functionality inside docker)