简体   繁体   中英

How to inject docker environment variable inside Spring boot application

I am using dockerized images to run on AWS ECS containers.

dockerfile :

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-Dspring.profiles.active=${profile}","-jar","/app.jar"]`

Is it possible for me to fetch this variable inside my spring boot class?

Want to use this to set profiles inside my spring boot application.

You can set Enviroment Variables within Dockerfile after "FROM" line, like this:

ENV JAVA_BASE="/opt/java"

For each variables you need to add a new "ENV" line.

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