简体   繁体   中英

Java System.getenv does not resolve environment variable defined in docker-compose

I have this sample 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.

 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM