[英]Dockerfile Spring Boot property from variable not working
I can't seem to get Spring boot properties to work via variable in my Dockerfile.我似乎无法让 Spring 引导属性通过我的 Dockerfile 中的变量工作。 This is what I am doing:
这就是我正在做的事情:
ENTRYPOINT exec java -Dapp-version=$app_version -jar /app.jar
If I do RUN echo "App Version: $app_version"
inside of my Dockerfile then I get then I get the correct output like App Version: 1.70.0
.如果我在 Dockerfile 中执行
RUN echo "App Version: $app_version"
那么我得到了正确的 output ,例如App Version: 1.70.0
。
If I manually put the version like this: ENTRYPOINT exec java -Dapp-version=1.70.0 -jar /app.jar
then the value is injected correctly.如果我手动输入这样的版本:
ENTRYPOINT exec java -Dapp-version=1.70.0 -jar /app.jar
那么该值被正确注入。
In fact, if I do RUN echo "ENTRYPOINT exec java -Dapp-version=$app_version -jar /app.jar"
then I get output like实际上,如果我执行
RUN echo "ENTRYPOINT exec java -Dapp-version=$app_version -jar /app.jar"
那么我会得到 output 之类的
Step 9/10 : RUN echo "ENTRYPOINT exec java -D******ion=$app_version -jar /app.jar"
---> Running in b6c3cd9bb69a
ENTRYPOINT exec java -D******ion=1.70.0 -jar /app.jar
The value inside of Spring is being set as an empty string when I use the Dockerfile variable.当我使用 Dockerfile 变量时,Spring 内部的值被设置为空字符串。 When I hard code it to 1.70.0 then it is being set correctly.
当我将它硬编码为 1.70.0 时,它被正确设置。 What am I missing?
我错过了什么?
I have tried many different things including using {}, quotes, etc.我尝试了许多不同的方法,包括使用 {}、引号等。
Edit: Added Dockerfile编辑:添加 Dockerfile
FROM java:8
ARG app_version
RUN echo -------------------
RUN echo "App Version: $app_version"
RUN echo -------------------
VOLUME /tmp
COPY ./build/libs/mango-sticky-rice-1.0.0-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT exec java -Dapp-version=$app_version -jar /app.jar
I've eddited this answer:我编辑了这个答案:
I think this might work我认为这可能有效
ENTRYPOINT ["java", "-Dapp-version=$app_version", "-jar", "/app.jar"]
This answer worked: https://stackoverflow.com/a/49889134/3088642 .这个答案有效: https://stackoverflow.com/a/49889134/3088642 。 This is what my Dockerfile looks like:
这就是我的 Dockerfile 的样子:
FROM java:8
ARG app_version
RUN echo -------------------
RUN echo "App Version: ${app_version}"
RUN echo -------------------
VOLUME /tmp
COPY ./build/libs/mango-sticky-rice-1.0.0-SNAPSHOT.jar /app.jar
RUN bash -c 'touch /app.jar'
RUN echo "#!/bin/bash \n java -Dapp-version=${app_version} -jar /app.jar" > ./entrypoint.sh
RUN chmod +x ./entrypoint.sh
RUN cat ./entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.