[英]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.