我有一个简单的spring-boot项目:
-resources
-application.yaml
-application-test.yaml
我有这个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)我建立图像 - C:\micro-boot>docker build -f Dockerfile -t micro-boot .
2)显示所有图像 - C:\micro-boot>docker image ls -a
micro-boot latest ccc9a75ebc24 4 seconds ago 112MB
3)尝试启动C:\micro-boot>docker image ls -a
我收到一个错误:
/bin/sh: [java,-Dspring.profiles.active=test: not found
这里有一个错字
ENTRYPOINT ["java","-Dspring.profiles.active=test" comma missing here "-jar","/micro-boot.jar"
]
我们有3种方式:
1.在Dockerfile中传递Spring Profile
FROM openjdk:8-jre-alpine
...
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=test","-jar","app.jar"]
2.在Docker运行中传递Spring Profile
docker run -d -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=test" --name my-app:latest
3.在Docker Compose中传递Spring Profile
version: "3.5"
services:
my-app:
image: my-app:latest
ports:
- "8080:8080"
environment:
- "SPRING_PROFILES_ACTIVE=test"