Check from the CLI if a cattle port is taken

I have a script that deploys database instances on a dynamic principle by using the rancher CLI commands. Is there a way to check whether a certain port is taken?

F.e. I want to spin up a Postgres container and export port 8001 on my cattle. Therefore, first check if the port is taken. If not - start the DB container. Otherwise, try 8002, and so on.

Is there a way for that through the CLI?

That info exists in the database/API, but there’s not a CLI command to get it… normally if you want a random available port you’d just ask for one and it gets allocated by the server.

I just realized my post might’ve been a bit misleading - it’s a container that I want to start, but not a DB server directly on the cattle.

So, my point is that I need to know of a free port that I can use before I start the container, cuz I need to put it in the docker-compose.yml config so I can export the Postgres default port on it.