Htaccess should not use anyway, even if there would be Apache2 fronf of Discourse — and there isn’t.
Docker makes life more complicated
and I don’t know how to handle it. But you can put Nginx (or what ever server/reserve proxy) before Discourse if you want. And then such redirection should be quite trivial task. You can do something like this:
But why would you like to redirect 404s back to frontpage in the first place? If an user is looking for something and gets frontpage instead wanted or 404, it it a bit confusing. And after that same user will try again because perhaps she/he did something wrong or that site had an issue. Totally unnecessary and there is reason why every site should show error 404 instead some strange redirection.