简体   繁体   中英

External config in Spring Boot application within Dockerfile

I want to run this Dockerfile application:

FROM java:8-jre
ADD config/ /deploy/
COPY ./meta.std.1.0.1.jar /deploy/
CMD chmod +x ./deploy/meta.std.1.0.1.jar
CMD ["java","-jar","/deploy/meta.std.1.0.1.jar","metastore","spring.config.location=./config/metadata-server.yml"]
EXPOSE 3011

While running, it's not reading the metadata-server.yml values? Is this the correct way?

I think that you put the wrong path of metadata-server.yml

"spring.config.location=./config/metadata-server.yml"

I think that after:

ADD config/ /deploy/

the path of metadata-server.yml should be:

"spring.config.location=/deploy/config/metadata-server.yml"

Use

FROM java:8-jre
ADD config/ /deploy/
COPY ./meta.std.1.0.1.jar /deploy/
CMD chmod +x ./deploy/meta.std.1.0.1.jar
CMD ["java","-jar","/deploy/meta.std.1.0.1.jar","metastore","--spring.config.location=classpath:file:/deploy/metadata-server.yml"]
EXPOSE 3011

Update:

Or better try this

FROM alpine:edge

VOLUME /tmp

RUN apk --no-cache upgrade && apk --no-cache add openjdk8-jre

ADD config/ /deploy/
COPY ./meta.std.1.0.1.jar /deploy/
ADD /YOUR/CONFIG/metadata-server.yml /deploy/metadata-server.yml

EXPOSE 3011

ENTRYPOINT ["java" ,"-Djava.security.egd=file:/dev/./urandom --spring.config.location=classpath:file:/deploy/metadata-server.yml","-jar","/deploy/meta.std.1.0.1.jar"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM