Is it ok to logout after calling docker stack deploy?
It is safe. As soon as docker returns it is safe to logout/leave the shell.

The issue was that Docker 18.06.0-ce broke docker stack deploy. Reverting to 18.03.1 (specifically 18.03.1~ce-0~ubuntu) made it work.