Exposing spring boot random server port using docker
We plan to deploy multiple docker images on same VM running same app. In my knowledge, we need to expose webapp port in docker container. But if we plan to use “random” server port in spring boot (using server.port=0), how we expose that random port at run time?
Second question is, does spring boot app picks random port which is available in host VM or just docker container space?
One Solution collect form web for “Exposing spring boot random server port using docker”
Spring-boot allocate the port at the run time, not at the build time. That means, the port selected by spring boot will not be available until you start the application natively or in the docker container.
Answer to your second question is that Docker pick the port inside the Docker Container. So, practically all the ports will be available other than the ones used by OS.
When combining these two statements, unless you have any specific restrictions, you should specify the port manually to spring-boot application and expose it at
docker run execution?