How can I start spring boot application in docker with profile?

旧时模样 提交于 2021-02-18 22:43:31

问题


I have a simple spring-boot project:

-resources
 -application.yaml
 -application-test.yaml

And I have this Dockerfile:

FROM openjdk:8-jdk-alpine
EXPOSE 8080
ADD micro-boot.jar micro-boot.jar
ENTRYPOINT ["java","-Dspring.profiles.active=test" "-jar","/micro-boot.jar"]

1) I build image - C:\micro-boot>docker build -f Dockerfile -t micro-boot .

2) show all images - C:\micro-boot>docker image ls -a

micro-boot   latest  ccc9a75ebc24  4 seconds ago 112MB

3) try to start C:\micro-boot>docker image ls -a

And I get an error:

/bin/sh: [java,-Dspring.profiles.active=test: not found

回答1:


There's a typo here

ENTRYPOINT ["java","-Dspring.profiles.active=test" comma missing here "-jar","/micro-boot.jar"]




回答2:


We have 3 ways:

1. Passing Spring Profile in a Dockerfile

FROM openjdk:8-jre-alpine
...
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=test","-jar","app.jar"]

2. Passing Spring Profile in Docker run

docker run -d -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=test" --name my-app:latest

3. Passing Spring Profile in DockerCompose

version: "3.5"
services:
  my-app:
     image: my-app:latest
     ports:
       - "8080:8080" 
     environment:
       - "SPRING_PROFILES_ACTIVE=test"


来源:https://stackoverflow.com/questions/55752013/how-can-i-start-spring-boot-application-in-docker-with-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!