You got me on the right tracks. Thanks a lot!
In my case there were two reasons.
I've edited cms/config/database.js according to what copilot said (not very good idea). Next time I'll just check the docs.
I wasn't copying .env file while preparing docker image.
So I guess missing env variables and incorrect database.js can cause this issue.