Ok, I know what went wrong. I used localhost as database host for Flarum, that is run in php container. It is run in bridged network mode, so ot has it's private IP. From it's perspective localhost is itself... but it doesn't have mysql in it! I had to use mariadb sd host, and 3306 as port, because this is mysql containter's hostname.
If anyone is interested, I can give some broader instructions on how to setup Docker environment for php development.