[英]Java System.getenv does not resolve environment variable defined in docker-compose
I have this sample docker-compose.yml:我有这个示例 docker-compose.yml:
version: "2"
networks:
default:
external:
name: simple-monitor_zeebe_network
services:
ods:
container_name: auto-auction-service
image: cargeeks/auto-auction-service:SNAPSHOT
environment:
- SERVICE_LOG_LEVEL=debug
- client.broker.contactPoint=172.20.0.6:26500
ports:
- "9200:7100"
networks:
- default
Somewhere in my microservice, I have code like this which attempts to resolve the client.broker.contactPoint environment variable.在我的微服务的某个地方,我有这样的代码试图解析client.broker.contactPoint环境变量。
String contactPoint = System.getenv("client.broker.contactPoint");
if (StringUtils.isEmpty(contactPoint)) {
_logger.info("Environment variable " + ENV_CONTACT_POINT + " is not defined. Using default " + DEFAULT_CONTACT_POINT);
contactPoint = DEFAULT_CONTACT_POINT;
}
When I run docker-compose up
against the docker-compose.yml file defined above, the contactPoint is always defined to the DEFAULT_CONTACT_POINT.当我针对上面定义的 docker-compose.yml 文件运行 docker docker-compose up
时,contactPoint 始终定义为 DEFAULT_CONTACT_POINT。
What am I doing wrong here?我在这里做错了什么?
Try without a dot-separated variable name.尝试不使用点分隔的变量名称。 Some environments either do no allow this or try and interpret them as a hierarchical reference.某些环境要么不允许这样做,要么尝试将它们解释为分层引用。 Use underscores instead, both in the Docker-compose file and the code.在 Docker-compose 文件和代码中改用下划线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.