我的Dockerfile中有以下内容来运行Springboot应用程序:
ENTRYPOINT [ "java", "-jar", "/code/myapp/target/myapp.jar", "--spring.profiles.active=$ENV_PROFILE"]
我在k8 YAML配置中将环境变量(ENV_PROFILE)定义为:
spec:
containers:
- name: myspringboot
image: myrepo/myapp:latest
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: ENV_PROFILE
value: "test"
然而,环境名称并没有被注入到java springboot应用程序中。它在日志中显示为"$ENV_PROFILE“。我也尝试过通过添加spring.profiles.active=$ENV_PROFILE
来使用application.properties,但也不起作用。
发布于 2019-04-19 20:42:13
默认情况下,您还可以覆盖Spring属性(以及应用程序属性中定义的其他属性),而无需指定要在属性文件中传递的环境变量。环境变量的优先级高于属性文件值。
另请参见Spring Externalized Configuration。
例如:
spec:
containers:
- name: myspringboot
image: myrepo/myapp:latest
imagePullPolicy: Always
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: SPRING_PROFILES_ACTIVE
value: "test"
发布于 2019-04-19 20:48:25
这是因为您没有在入口点中使用shell。只有shell可以进行环境变量替换。在您的示例中,您可以使用以下入口点:
ENTRYPOINT exec java -jar /code/myapp/target/myapp.jar --spring.profiles.active=$ENV_PROFILE
此语法涉及到调用“/bin/ sure入口点”,“-c”确保容器内的-c将变为PID1。
https://stackoverflow.com/questions/55761930
复制相似问题