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?

  • Docker how to start container with defined nameservers in /etc/resolv.conf
  • Unable to access jarfile when running Docker image
  • How to set static IP address to a container running into a Swarm over a weave-overlay network?
  • docker COPY with file globbing
  • Docker port forwarding stops working after ip of host machine is changed
  • How to map ports with - Express + Docker + Azure
  • Where to find geard deployment fixture/config documentation?
  • How to run cucumber/selenium tests in Docker?
  • hub.docker.io reports tags in the web interface but we cannot some of them using the API
  • How to completely destroy docker container from marathon UI?
  • error when I make peer in my virtual box
  • Docker run - User group not working as expected?
  • 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.