Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
Spring Boot can't read application.properties in Docker

Spring Boot doesn't read application properties when running in Docker container.

My application.yml

server:
  port: 8080
  context-path: /mail
custom:
  greeting: Hello YML

Dockerfile

FROM java:8-jre
VOLUME /tmp
COPY ./mail.jar /app/mail.jar
RUN sh -c 'touch /app/mail.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app/mail.jar" ]
EXPOSE 8080

And a simple ApplicationController

@RestController
public class ApplicationController {

  private final Environment environment;

  @Autowired
  public ApplicationController(Environment environment) {
    this.environment = environment;
  }

  @RequestMapping(path = "/")
  public Hello hello() {
    final Hello hello = new Hello();
    hello.setGreeting(environment.getProperty("custom.greeting"));
    return hello;
  }
}

I'm using IntelliJ Docker plugin that automatically map ports 8080(docker):18080(host) and makes app available on http://localhost:18080

Docker

  1. server.context-path property isn't applied. App still available with / and not with /mail/
  2. custom.greeting property not reads from properties file and controller returns {"greeting":null} instead {"greeting":"Hello YML"}

Without Docker

  1. context-path applied properly

  2. custom.greeting property returns by controller properly

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You have to add the application.properties file in the docker /app/ directory. Ur docker directory structure will be

app
   -main.jar
   -application.properties

You can do so by using ADD /ur/local/location/application.properties /app/application.properties

Then better write this command in your docker file

ENTRYPOINT ["java" ,"-Djava.security.egd=file:/dev/./urandom --spring.config.location=classpath:file:/app/application-properties","-jar","/app/main.jar"]

Your whole dockerFile should look like this:

FROM java:8-jre
VOLUME /tmp
COPY ./mail.jar /app/mail.jar
ADD /ur/local/location/application.properties /app/application.properties
ENTRYPOINT ["java" ,"-Djava.security.egd=file:/dev/./urandom --spring.config.location=classpath:file:/app/application-properties","-jar","/app/main.jar"]
EXPOSE 8080
about 4 years ago · Santiago Trujillo Denunciar

0

Rename Application.yml to application.yml. It's with reference to the name used in the comments as Application.yml.

Application.yml works well with widows but breaks inside linux containers.

about 4 years ago · Santiago Trujillo Denunciar

0

For the context path, you have to add the context path in the properties file. inside the application-default.properties:

server.servlet.contextPath=/myContext

Then build your project,

mvn clean install

Then create a docker image and run that image.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda