I have a CF application that opens two ports. AFAIK CF can create routing on only for one of them - to the one that is located in VCAP_APP_PORT
or PORT
As stated in some other comments it is now possible in CF to use multiple ports for your application. There is a chapter in the CF documentation which describes how to do it. I followed the instructions and still had some trouble to fully understand it, that's why I provide a step by step guide here with some explanations (replace all variables in [] with the actual values):
cf app [APP_NAME] --guid
cf curl /v2/apps/[APP_GUID] -X PUT -d '{"ports": [8080, 8081]}'
cf curl /v2/routes?q=host:[HOST_NAME]
or with cf curl /v2/apps/[APP_GUID]/routes
and save the guid of the route that points to your app ([ROUTE_GUID]).cf curl /v2/routes/[ROUTE_GUID]/route_mappings
. With cf curl /v2/route_mappings -X POST -d '{"app_guid": "[APP_GUID]", "route_guid": "[ROUTE_GUID]", "app_port": 8081}'
you add a mapping to a route (e.g. here to 8081).cf curl /v2/routes/[ROUTE_GUID]/route_mappings
to show all route mappings. Then extract the guid of the route mapping that should be deleted (e.g. the one to port 8080). Finally, run cf curl /v2/route_mappings/[GUID_ROUTE_MAPPING] -X DELETE
to delete the route mapping you do not need.Now your CF app should be reachable on another port than 8080 when the newly configured route is used.
Currently an application on Cloud Foundry is not able to have two ports mapped into its container environment. As part of the new Diego runtime, multiple port mappings has been exposed, but is not currently available through the API.
Depending on what you need, you could take a look at Lattice, which uses the Diego runtime. Some documentation can be found here.
Resurrecting an old question, but this is supported in Cloud Foundry now. Support was added around April 2019. Check your version to see if it supports this.
The general process is:
Right now you have to use cf curl
to manually update these records. Instructions can be found here: https://docs.cloudfoundry.org/devguide/custom-ports.html. Hopefully future cf cli versions make this easier.
Cloud Foundry will route TCP/WebSocket traffic coming from 80/443 to the one assigned port. Your application can not listen to any other port.
https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#ports
You can either create multiple url mappings, or have two applications that communicate with each other using a messaging or database service.