简体   繁体   中英

Spring Cloud Config Server Won't Serve from Local Filesystem

Note: I've read this and this question. Neither helped.

I've created a Spring config server Docker image. The intent is to be able to run multiple containers with different profiles and search locations. This is where it differs from the questions above, where the properties were either loaded from git or from classpath locations known to the config server at startup. My config server is also deployed traditionally in Tomcat, not using a repackaged boot jar.

When I access http://<docker host>:8888/movie-service/native , I get no content (see below). The content I'm expecting is given at the end of the question.

{"name":"movie-service","profiles":["native"],"label":"master","propertySources":[]}

I've tried just about everything under the sun but just can't get it to work.


Config server main:

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class ConfigServer extends SpringBootServletInitializer {
    /* Check out the EnvironmentRepositoryConfiguration for details */
    public static void main(String[] args) {
        SpringApplication.run(ConfigServer.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ConfigServer.class);
    }
}

Config server application.yml :

spring:
  cloud:
    config:
      enabled: true
      server:
        git:
          uri: ${CONFIG_LOCATION}
        native:
          searchLocations: ${CONFIG_LOCATION}
server:
  port: ${HTTP_PORT:8080}

Config server bootstrap.yml :

spring:
  application:
    name: config-service

eureka:
  instance:
    hostname: ${CONFIG_HOST:localhost}
    preferIpAddress: false
  client:
    registerWithEureka: ${REGISTER_WITH_DISCOVERY:true}
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${DISCOVERY_HOST:localhost}:${DISCOVERY_PORT:8761}/eureka/

Docker run command :

docker run -it -p 8888:8888 \
-e CONFIG_HOST="$(echo $DOCKER_HOST | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')" \
-e HTTP_PORT=8888 \
-e CONFIG_LOCATION="file:///Users/<some path>/config/" \
-e REGISTER_WITH_DISCOVERY="false" \
-e SPRING_PROFILES_ACTIVE=native xxx

Config Directory :

/Users/<some path>/config
--- movie-service.yml

Content of movie-service.yml :

themoviedb:
  url: http://api.themoviedb.org

Figured this out myself. The Docker container doesn't have access to the host file system unless the file system directory is mounted at runtime using a -v flag.

For the sake of completeness, this is the full working Docker run command:

docker run -it -p 8888:8888 \
-e CONFIG_HOST="$(echo $DOCKER_HOST | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}')" \
-e HTTP_PORT=8888 \
-e CONFIG_LOCATION="file:///Users/<some path>/config/" \
-e REGISTER_WITH_DISCOVERY="false" \
-e SPRING_PROFILES_ACTIVE=native \
-v "/Users/<some path>/config/:/Users/<some path>/config/" \
xxx

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