We shall try to quickly start a spring boot cloud config server using local folder to load properties using "hyness/spring-cloud-config-server".
Note: This docker image is not an official Spring Boot image. So I do not recommend using in industry level applications. I would rather suggest building your own cloud config server which I may cover in another post.
Configuration hosted on local folder
docker run --name configservice -p 8080:8888 -e SPRING_PROFILES_ACTIVE=native -v /Users/hsingh/config-files:/config -d hyness/spring-cloud-config-server
Explaination of parameters:
--name: name of docker container that is created
-p: exposing port 8888 inside container as port 8080 for local system
-e: parameters to docker container
SPRING_PROFILE_ACTIVE --> tells spring boot cloud config service to use native profile i.e. use a local folder to serve configuration
-v: mounting a local folder as a volume inside docker container. This local folder shall contain config files
-d: run in detached mode i.e. start container and return for next command. Otherwise container logs will start tailing
My config files are hosted on local folder "/Users/hsingh/config-files".
Testing:
Configuration hosted on GIT
Assume that config files are hosted on "https://github.com/spring-cloud-samples/config-repo".
docker run -it -p 8080:8888 -e SPRING_CLOUD_CONFIG_SERVER_GIT_URI=https://github.com/spring-cloud-samples/config-repo -d hyness/spring-cloud-config-server
I would rather prefer using local folder to serve properties, than using local git. Because making a small change would mean committing to git. But here it is:
docker run -it -p 8080:8888 -v /path/to/config/files/dir:/config -e SPRING_CLOUD_CONFIG_SERVER_GIT_URI=file:/config/my-local-git-repo -d hyness/spring-cloud-config-server
Note: This docker image is not an official Spring Boot image. So I do not recommend using in industry level applications. I would rather suggest building your own cloud config server which I may cover in another post.
Configuration hosted on local folder
docker run --name configservice -p 8080:8888 -e SPRING_PROFILES_ACTIVE=native -v /Users/hsingh/config-files:/config -d hyness/spring-cloud-config-server
Explaination of parameters:
--name: name of docker container that is created
-p: exposing port 8888 inside container as port 8080 for local system
-e: parameters to docker container
SPRING_PROFILE_ACTIVE --> tells spring boot cloud config service to use native profile i.e. use a local folder to serve configuration
-v: mounting a local folder as a volume inside docker container. This local folder shall contain config files
-d: run in detached mode i.e. start container and return for next command. Otherwise container logs will start tailing
My config files are hosted on local folder "/Users/hsingh/config-files".
Testing:
hsingh-15mbp:hsingh config-files $ curl http://localhost:8080/accountservice/default | json_pp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 278 0 278 0 0 2353 0 --:--:-- --:--:-- --:--:-- 2355
{
"version" : null,
"state" : null,
"propertySources" : [
{
"source" : {
"service" : "Account Service"
},
"name" : "file:config/accountservice.properties"
},
{
"source" : {
"message" : "Hello World"
},
"name" : "file:config/application.properties"
}
],
"name" : "accountservice",
"label" : null,
"profiles" : [
"default"
]
}
Note: any changes made to config properties will be immediately reflected on config service.
Configuration hosted on GIT
Assume that config files are hosted on "https://github.com/spring-cloud-samples/config-repo".
docker run -it -p 8080:8888 -e SPRING_CLOUD_CONFIG_SERVER_GIT_URI=https://github.com/spring-cloud-samples/config-repo -d hyness/spring-cloud-config-server
I would rather prefer using local folder to serve properties, than using local git. Because making a small change would mean committing to git. But here it is:
docker run -it -p 8080:8888 -v /path/to/config/files/dir:/config -e SPRING_CLOUD_CONFIG_SERVER_GIT_URI=file:/config/my-local-git-repo -d hyness/spring-cloud-config-server
Comments
Post a Comment