A common trap is to read an empty ufw status as proof that a container port is closed. Docker writes its own iptables rules, and traffic to published ports skips the ufw chains.
docker run -d -p 127.0.0.1:8080:80 nginx
sudo iptables -L DOCKER-USER -n
A plain -p 8080:80 binds on all interfaces and is reachable from outside no matter what ufw says. Binding to 127.0.0.1 keeps it local, and a reverse proxy on the same host can still reach it. For rules that apply to published ports, add them to the DOCKER-USER chain, which Docker evaluates first. Docker documents this in its packet filtering and firewalls page.
Further reading: Docker packet filtering and firewalls