简体   繁体   中英

Rancher CLI random host port mapping

I am planning to use rancher for managing my containers. On my dev box, we plan to bring up several containers each serving a REST api.

I am able to automate the process of building up my containers using jenkins and want to run the container using rancher to take advantage of random host port mapping. I am able to do this using rancher UI but unable to find the way to automate it using cli.

ex: Jennkins builds Container_A exposes 8080 -> Jenkins also executes rancher cli to run the container mapping 8080 to a random port of host. And the same for Container_B exposing 8080.

Hope my question makes sense. Thanks Vijay

You should just be able to do this in the service definition in the Docker compose yaml file:

... publish: 8080 ...

If you generate something in the UI and look at the configuration of the stack, you'll see the corresponding compose yml.

Alternatively, you can use:

rancher run --publish 8080 nginx

then get the randomly assigned port:

rancher inspect <stackname>/<service_name> | jq .publicEndpoints[].port

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM