Is it possible to block all outgoing connections to a specific port?

Hello.

I need to make requests from a container to a specific port impossible.

For example, I want to block port 5432 so that I cannot make TCP/UPD requests to *:5432 from my container:

5.6.7.8:5432
9.10.11.12:5432

But at the same time, inside the container it would be possible to access the port:

127.0.0.1:5432

Is it possible?