Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 392
Ashish Jain Avatar asked May 21 '26 04:05

Ashish Jain


1 Answers

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?

like image 69
techtabu Avatar answered May 22 '26 20:05

techtabu