This topic shows you how to run the Spring Config Server standalone JAR.
-
Create an image from the Config Server JAR file. The easiest way to do this is to use the
pack
command:pack build tanzu/config-server:1.0.0 \ --path ./config-server-tsr-1.0.0.jar \ --builder paketobuildpacks/builder:tiny
-
If you will be running the image on an ARM host (such as an Apple machine with an Apple chipset), you must use a different builder:
pack build tanzu/config-serverx:1.0.0 \ --path ./config-server-tsr-1.0.0.jar \ --builder dashaun/builder:tiny
-
Alternatively, you can create an image using
docker build
. Create a Dockerfile with the following contents:FROM openjdk:17-jdk COPY config-server-1.0.0.jar cs.jar ENTRYPOINT [ "java", "-jar", "cs.jar" ]
This assumes that the JAR file is in the directory where you will create the image. Using the Docker CLI, create the image with this command (substitute “tanzu” with your organization’s Docker repository name):
docker build -t "tanzu/config-server:1.0.0" .
-
-
Create a configuration file. The example shown here is the minimum required. Your configuration is expected to be more comprehensive.
spring: cloud: config: server: git: uri: https://github.com/spring-cloud-services-samples/cook-config
-
Make the configuration available to the container. The most basic way of doing this is to use a bind mount to mount a directory containing the configuration YAML file. For example, if the
config-server.yml
file is in a directory namecsconfig
, start the container by running:docker run -d \ -p 8888:8888 \ --mount type=bind,source="$(pwd)"/csconfig,target=/csconfig -e SPRING_CONFIG_IMPORT='/csconfig/config-server.yml' tanzu/config-server:1.0.0
This starts the container, forwards the local port 8888 to the Config Server’s port 8888 running in the container, and sets the
SPRING_CONFIG_IMPORT
environment variable to reference the mounted configuration file. -
Test it by making a request to the Config Server using curl:
curl localhost:8888/application/default
Content feedback and comments