Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

517
Visualizações
Java Spring Boot Random Port with Dockerfile

If you're using Java Spring Boot, you can set the server port the application runs on to any port, but also to a random port:

server:
  port: 0

However, when I now use a Dockerfile for my application, I won't know what port to EXPOSE. Is there any way to find this port?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

  1. Don't use a random port for the Spring app. Use the default port and have Docker expose that as whatever port you like.
  2. Don't use a random port for the Spring app. Specify it via an environment variable and have Docker provide that.
over 4 years ago · Santiago Trujillo Relatório

0

when you started an app, you can see at console I think. As I know docker use 8080 or 8081.

EDIT 1: Check this -> link

You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls).

You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag. This will bind the exposed port to your Docker host on port 80, and it expects the exposed port is 80 too (adjust as necessary with HOST:CONTAINER).

You can ignore exposing anything and just use -p 80:80 in which case this doubles as both exposing AND publishing the port.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda