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?

  • Container process on host machine
  • gulp not running on Docker ubuntu
  • Multiple docker containers as web server on a single IP
  • I can't access mounted volume of docker-postgres from host
  • Using jenkins docker image
  • Can't pull image from private docker registry
  • Windows Docker Toolbox won't start
  • How to reach a linked service in docker-compose?
  • Datadog integration inside docker containers
  • Docker Exec command does not work properly
  • Ruby Remote SDK configuration with Intellij broken - workarround?
  • Can I store npm scripts outside of package.json, to avoid forcing Docker to refresh all modules on any npm script update?
  • 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?

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.