Locking down a fresh Linux server: What you actually need to do before bots find it
(unknownuniverse.uk)
I'll have to find the post again (it was somewhere here on Lemmy) but UFW does not apply to docker containers.
Docker bypasses UFW because it uses iptables and UFW doesn't support firewall zones.
Any docker/podman ports not bound to localhost will be publicly accessible even if you have a block rule on UFW.
There are some wacky script workarounds but the real solution is to install & use a proper firewall like firewalld (firewall-cmd command) and not the joke utilities of Canonical/Ubuntu (ufw, netplan, etc).
At which point you might as well chuck Ubuntu into the trash since you'd be replacing a bunch if its defaults anyway, and just stick with Debian or another quality stable distro like OpenSUSE.