Exposing spring boot random server port using docker
up vote
0
down vote
favorite
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 spring-boot
add a comment |
up vote
0
down vote
favorite
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 spring-boot
1
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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 spring-boot
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 spring-boot
docker spring-boot
asked Jun 24 '16 at 19:13
Ashish Jain
104311
104311
1
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23
add a comment |
1
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23
1
1
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
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?
Don't we need to specific port to be exposed, at time ofdocker run
command. docker run will start container and at start of container, spring boot app will start.
– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,net=host
option might work for me. It will expose OS network stack to container env.
– Ashish Jain
Jun 24 '16 at 20:28
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.docker run -p 3000 my_image
will make docker expose the service in a random port.
– Shibashis
Jun 24 '16 at 22:12
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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?
Don't we need to specific port to be exposed, at time ofdocker run
command. docker run will start container and at start of container, spring boot app will start.
– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,net=host
option might work for me. It will expose OS network stack to container env.
– Ashish Jain
Jun 24 '16 at 20:28
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.docker run -p 3000 my_image
will make docker expose the service in a random port.
– Shibashis
Jun 24 '16 at 22:12
add a comment |
up vote
1
down vote
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?
Don't we need to specific port to be exposed, at time ofdocker run
command. docker run will start container and at start of container, spring boot app will start.
– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,net=host
option might work for me. It will expose OS network stack to container env.
– Ashish Jain
Jun 24 '16 at 20:28
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.docker run -p 3000 my_image
will make docker expose the service in a random port.
– Shibashis
Jun 24 '16 at 22:12
add a comment |
up vote
1
down vote
up vote
1
down vote
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?
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?
answered Jun 24 '16 at 19:52
techtabu
2,1851320
2,1851320
Don't we need to specific port to be exposed, at time ofdocker run
command. docker run will start container and at start of container, spring boot app will start.
– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,net=host
option might work for me. It will expose OS network stack to container env.
– Ashish Jain
Jun 24 '16 at 20:28
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.docker run -p 3000 my_image
will make docker expose the service in a random port.
– Shibashis
Jun 24 '16 at 22:12
add a comment |
Don't we need to specific port to be exposed, at time ofdocker run
command. docker run will start container and at start of container, spring boot app will start.
– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,net=host
option might work for me. It will expose OS network stack to container env.
– Ashish Jain
Jun 24 '16 at 20:28
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.docker run -p 3000 my_image
will make docker expose the service in a random port.
– Shibashis
Jun 24 '16 at 22:12
Don't we need to specific port to be exposed, at time of
docker run
command. docker run will start container and at start of container, spring boot app will start.– Ashish Jain
Jun 24 '16 at 20:27
Don't we need to specific port to be exposed, at time of
docker run
command. docker run will start container and at start of container, spring boot app will start.– Ashish Jain
Jun 24 '16 at 20:27
I also read somewhere,
net=host
option might work for me. It will expose OS network stack to container env.– Ashish Jain
Jun 24 '16 at 20:28
I also read somewhere,
net=host
option might work for me. It will expose OS network stack to container env.– Ashish Jain
Jun 24 '16 at 20:28
1
1
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.
docker run -p 3000 my_image
will make docker expose the service in a random port.– Shibashis
Jun 24 '16 at 22:12
The comment from @dunni is accurate. You can start the app on same port and let docker expose the service on a random port on the host.
docker run -p 3000 my_image
will make docker expose the service in a random port.– Shibashis
Jun 24 '16 at 22:12
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38020567%2fexposing-spring-boot-random-server-port-using-docker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
If you have one application per container, you can use the same port for each of the application. The docker containers have their own separate ports, independent of the host system or other containers. You would then specify the mapping from a host port to the container port when you run the container.
– dunni
Jun 24 '16 at 21:23