1

I have all of my microservices using Spring Cloud (Config Server, Eureka Server, API Gateway, and the services) working interdependently and running perfectly fine in my local computer. But I am having problem running them in a docker container because I believe Eureka Server and other services not picking up properties from the Config Server.

I was able to run the Config Server in a container without problem at port 8888 but others not. Eureka Server always runs on the default port 8080 even if I specified 8761 in the properties file, then it fails after a few seconds. Below are my docker and properties files.

Here is my Config Server's bootstrap.properties:

server.port = 8888
spring.cloud.config.server.native.searchLocations = file:///${user.home}/config-repo
spring.profiles.active = native


I am referencing to the Config Server from Eureka Server through this:

spring.cloud.config.uri = http://localhost:8888


And here is my Eureka Server's properties:

server.port = 8761
eureka.client.register-with-eureka = false
eureka.client.fetch-registry = false


Here is my Config Server's dockerfile:

FROM alpine-jdk:base
MAINTAINER javaonfly
COPY files/config-service.jar /opt/lib/
RUN mkdir /var/lib/config-repo
COPY config-repo /var/lib/config-repo
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/lib/config-service.jar"]
VOLUME /var/lib/config-repo
EXPOSE 8888


Here is my Eureka Server's dockerfile:

FROM alpine-jdk:base
MAINTAINER javaonfly
COPY files/eureka-service.jar /opt/lib/
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/lib/eureka-service.jar"]
EXPOSE 8761


Here is my Docker Compose file:

version: '2.2'
services:
    config-service:
        container_name: config-service
        build:
            context: .
            dockerfile: Dockerfile-configservice
        image: config-service:latest
        expose:
            - 8888
        ports:
            - 8888:8888
        networks:
            - emp-network
        volumes:
            - config-repo:/var/lib/config-repo
    eureka-service:
        container_name: eureka-service
        build:
            context: .
            dockerfile: Dockerfile-eurekaservice
        image: eureka-service:latest
        expose:
            - 8761
        ports:
            - 8761:8761
        networks:
            - emp-network
networks:
    emp-network:
        driver: bridge
volumes:
    config-repo:
        external: true

Hope anyone can help me with this so I can finally see them running in a docker container and I can be able to explore Kubernetes next.

Cœur
  • 37,241
  • 25
  • 195
  • 267
samihan
  • 31
  • 1
  • 1
  • 3
  • What docker image are you using (`alpine-jdk:base` doesn't exist in dockerhub)? What makes you think `${user.home}` is `/var/lib`? – Dave Syer Jul 24 '18 at 09:39
  • Hi sir Dave, i already have that base image in my local docker, then i just inherited that on my other dockerfile. I just don't know how to refer to the docker volume on searchLocations and that's what I wanted to ask. Can you help me with it sir? Thanks a lot! – samihan Jul 24 '18 at 10:46
  • A docker volume is just a directory. You don't have to treat it any differently. So I guess I don't understand the question. – Dave Syer Jul 24 '18 at 12:23
  • Maybe because of my bad english. I'm sorry for that. Maybe I should just try to set it to spring.cloud.config.server.native.searchLocations=file://config-repo and see if it works. Thanks! – samihan Jul 24 '18 at 13:16
  • My Eureka Server still doesn't get config from the config server even if i changed it to spring.cloud.config.server.git.uri = https://github.com/samihan/bootiful-microservices-config.git. I'm just wondering because Config Server and Eureka Server works fine in my local computer using both native and git uri, but in a docker container only the Config Server runs and Eureka Server doesn't. – samihan Jul 25 '18 at 02:14

1 Answers1

0

This is a bit late but i get the same issue. This is because you have to force the native profile with spring cloud config server.

The key point here is "SPRING_PROFILES_ACTIVE=native"

docker-compose.yml

services:
  config-server:
    image: springcommunity/config-server
    container_name: config-server
    mem_limit: 512M
    ports:
     - 8888:8888
    volumes:
     - config-server-vol:/usr/local/config-server
    environment:
     - "SPRING_PROFILES_ACTIVE=native"

Then you will see in the log of the config server container.

6] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:////usr/local/config-server/application.yml (document #0)

2021-09-22 07:46:32.949  INFO 1 --- [nio-8888-exec-7] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:////usr/local/config-server/visits-service.yml (document #1)

2021-09-22 07:46:32.970  INFO 1 --- [nio-8888-exec-7] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:////usr/local/config-server/application.yml (document #2)

2021-09-22 07:46:32.978  INFO 1 --- [nio-8888-exec-7] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:////usr/local/config-server/application.yml (document #1)
Zhar
  • 3,330
  • 2
  • 24
  • 25