简体   繁体   English

Docker运行时-e无法正常工作。无法在run命令中传递spring.profiles.active

[英]Docker run with -e not working.Failed to pass spring.profiles.active in the run command

I am facing one issue with my docker file.Image build was successful but while running I am getting an error because the active profile I am setting in the run command is not reflecting. 我遇到了我的docker文件的一个问题。图像构建成功但是在运行时我收到错误,因为我在运行命令中设置的活动配置文件没有反映。

# Get java
FROM openjdk:8-jdk-alpine


VOLUME /tmp
ARG JAR
COPY ${JAR} app.jar

EXPOSE 8080
ENV severn_js_key=1234qasw

ENTRYPOINT ["java", "-jar", "app.jar"]

My run command is like 我的运行命令就像

sudo docker run -e SPRING_PROFILES_ACTIVE=dev  -p 8088:80  -t tws-apps/service:1.0.0-SNAPSHOT

I am getting a null pointer exception in the server log while executing this statement 我在执行此语句时在服务器日志中获得空指针异常

String environment = System.getProperty("spring.profiles.active");
switch (environment) {

Please help 请帮忙

You pass the SPRING_PROFILES_ACTIVE to the docker container as a system environment variable. 您将SPRING_PROFILES_ACTIVE作为系统环境变量传递给SPRING_PROFILES_ACTIVE容器。 You should pass it as a Java System Property instead. 您应该将其作为Java System Property传递。 A solution would be to run the container by overriding the entrypoint: 解决方案是通过覆盖入口点来运行容器:

docker run --entrypoint java -t tws-apps/service:1.0.0-SNAPSHOT -Dspring.profiles.active=dev -jar app.jar

In alternative, in your Dockerfile change the entrypoint. 或者,在Dockerfile更改入口点。 It could be a script that reads the SPRING_PROFILES_ACTIVE environment variable and then runs Java with the var as a system property. 它可以是一个脚本,它读取SPRING_PROFILES_ACTIVE环境变量,然后使用var作为系统属性运行Java。

Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spring.profiles.active 在springboot应用程序中不起作用 - spring.profiles.active is not working in springboot application spring.profiles.active 不兑现 - spring.profiles.active not honoured spring - 用@ActiveProfiles 覆盖 spring.profiles.active - spring - override spring.profiles.active with @ActiveProfiles 在OS X中设置spring.profiles.active - setting spring.profiles.active in OS X 无法解析值“classpath:application-${spring.profiles.active}.properties”中的占位符“spring.profiles.active” - Could not resolve placeholder 'spring.profiles.active' in value “classpath:application-${spring.profiles.active}.properties” "无法解析值“classpath:\/ldap-${spring.profiles.active}.properties”中的占位符“spring.profiles.active”" - Could not resolve placeholder 'spring.profiles.active' in value "classpath:/ldap-${spring.profiles.active}.properties" 为什么 spring.profiles.active 只读取部分配置文件? - Why does spring.profiles.active only read some profiles? spring.profiles.active 未设置为在命令行上为 maven 构建指定的配置文件名称 - spring.profiles.active ist not set to the profile name specified on the command line for the maven build Spring 引导获取 static 块中的 spring.profiles.active 值 - Spring Boot get spring.profiles.active value in a static block Spring Boot - 如何为 spring.profiles.active = test 禁用 @Cacheable? - Spring Boot - How to disable @Cacheable for spring.profiles.active = test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM