Rancher catalog port range example

Does anyone happen to have an example of using the templating supported by Rancher to implement port ranges in the same way as Docker Compose does?

I’d like to create a catalog template where I can define 2 variables in rancher-compose something like this:

CONTAINER_PORTS=8000-8005
HOST_PORTS =8500-8505

that then get expanded in docker-compose:
ports:

  • 8000:8500
  • 8001:8501
  • 8002:8502
  • 8003:8503
  • 8004:8504
  • 8005:8505

Even better would obviously be that Rancher support this natively :wink:

While this should be doable, the way you’ve described is the most complicated to implement. The input is a string which requires parsing, and the 2nd half of HOST_PORTS is redundant because there has to be a 1:1 mapping, so you’re just doing extra work to parse and then throw it away.

The most straightforward way would be 3 variables: container_start=8000, container_count=6, and host_offset=500. You should be able to use those, range, until, and add to do what you want.

To do container_end instead of container_count or host_start instead of host_offset you need a little more math. There is actually also string splitting in sprig, so if you really want you can even use exactly the 2 variables you said.