One more thing worth mentioning: the underlying issue — your domain not being reachable from inside the container — is a classic split-brain DNS situation that every self-hoster eventually runs into, especially when hosting behind NAT. If you are not yet familiar with the concept, I would strongly recommend reading through this guide from our 101 series:
→ 101: Split-Brain DNS (split-horizon) ←
I consider this foundational knowledge for anyone hosting their own Nextcloud server. The /etc/hosts fix gets you going, but understanding split-brain DNS properly will save you from running into the same class of problem again in different forms.
ernolf