When I write username and password I can login but I don't know why I don't have to write full username with domain ?
It's depend from your IMAP server settings. I think by default your IMAP server setting just used name without domain part, so RC can login to IMAP just by name.
-----------
Second of my problem is after login I see user in domain mail.example.com but I want to domain example.com. When I add parametr in config.inc.php $config['username_domain'] ='example.com'; then I can't be able to log to roundcube.
Yes you can't login because:
You have server
mail.examlpe.com with local unix users - so your users will have logins like user@
mail.example.com or
mail.example.com\user - that you see when you login with username.
$config['username_domain'] ='example.com' Automatically add this domain to user names for login. And when your RC (roundcube) try login to IMAP server your login looks like: user@example.com - but its not look like existing users from step 1 (user@
mail.example.com) and your IMAP not setup for using full mail name as login - so this 2 reason why you have error.
-----------
I think you need 2 next step (not sure all is correct, but may be)
1. Change OS hostname from mail.example.com to example.com - so your users will have logins like user@example.com Instead of user@
mail.example.com . I hope its worked )
2. Setup your IMAP (dovecot) for login users by full name with domain only. Think it can be somewhere like /ect/dovecot/auth-system.conf.ext or similar place.
P.S.
may be better way will be find (google) tutorial "how to setup imap+smtp+dovecot server" with examples.