# Rancher catalog port range example

**URL:** <https://forums.suse.com/t/rancher-catalog-port-range-example/7303>\
**Category:** General\
**Created:** [September 10, 2017, 12:23pm UTC](https://forums.suse.com/t/rancher-catalog-port-range-example/7303 "2017-09-10T12:23:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Hansen](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/thomas_hansen/32/1283_2.png) [@Thomas\_Hansen](https://forums.suse.com/u/Thomas_Hansen)\
**Post date:** [September 10, 2017, 12:23pm UTC](https://forums.suse.com/t/rancher-catalog-port-range-example/7303/1 "2017-09-10T12:23:54Z")

</div>

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 😉

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [September 10, 2017, 11:36pm UTC](https://forums.suse.com/t/rancher-catalog-port-range-example/7303/2 "2017-09-10T23:36:04Z")

</div>

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](https://golang.org/pkg/text/template/), [until](http://masterminds.github.io/sprig/integer_slice.html), and [add](http://masterminds.github.io/sprig/math.html) 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](http://masterminds.github.io/sprig/), so if you really want you can even use exactly the 2 variables you said.
