I am trying to create and start a container from within my REST service method. My REST service is residing in an Unix machine and there would be multiple requests from external systems to configure and start multiple docker containers in the machine using my REST service that also resides in the same machine.
My question is how do I decide on which port I can start my container. Each request to my REST method should start a container on a unique port that has not been used in earlier requests. If I generate a random port number then I need some way to ensure that the same number is not regenerated, otherwise it would create a port conflict.
I need to generate a random port number each time, non repeating, store the used port list somewhere and check the list each time I generate a random number to make sure the port has not been used, release the port when the container is stopped (update the "ports-in-use" list to remove the stopped container). any idea on how to accomplish this in Java? Thanks in advance
Aucun commentaire:
Enregistrer un commentaire