0

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
Community
  • 1
  • 1
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • Could you add your Dockerfile here?, likely if you are missing content its not properly added to the image in the first place. Though, could you give a clearer picture of "nothing" ? :) A 404 ? – Armin Braun Dec 28 '15 at 00:50
  • @ArminBraun I did show what I meant by "nothing" - not sure how you missed it. It's one line below :) However, I figured out the issue myself. See my answer. – Abhijit Sarkar Dec 28 '15 at 00:52

1 Answers1

0

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
Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219