1

I have a very simple java jar application that fetches DB properties from the env variables. I`ve dockerized it and migrated to Kubernetes. I also created a config map and secret with parameters to my DB - so I have access to these properties in the container. Is it possible to fetch all properties and inject it in Dockerfile? How can I do it?

FROM openjdk:8-jre
ADD target/shopfront-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8010
ENTRYPOINT ["java","-Ddb.host=**value-from-env-variable**","-jar","/app.jar"]
michf
  • 209
  • 6
  • 17
  • 1
    Why do you want to inject it to the Docker file? i guess you mean inject it to the running kubernetes Pod which has your container – garlicFrancium Aug 21 '19 at 20:12
  • Exactly. I`ve already injected it from the config map to the pod - but I need to run the java jar app with these arguments. I think about fetching db env variables in docker file and using in entrypoint. My second idea is to use "command" arg in Kubernetes pod definition – michf Aug 21 '19 at 20:17
  • Possible duplicate of [How do I use Docker environment variable in ENTRYPOINT array?](https://stackoverflow.com/questions/37904682/how-do-i-use-docker-environment-variable-in-entrypoint-array) – Matt Aug 21 '19 at 23:42

3 Answers3

1

You can use them like this

ENTRYPOINT ["java", "-jar", "-Ddb.host=${DB_HOST}", "/app.jar"]

where DB_HOST should be defined in config map you have created.

I have tried this in my Spring Boot Application for setting Spring Profile.

Tarun Khosla
  • 1,274
  • 7
  • 10
1

The array or "exec form" of entrypoint uses exec to run the specified binary rather than a shell. Without a shell the string $DB_HOST is passed to your program as argument.

Shell form

ENTRYPOINT java -Ddb.host="${DB_HOST}" -jar /app.jar

Shell script

If your startup get more complex you can also use an ENTRYPOINT script.

ENTRYPOINT ["/launch.sh"]

Then launch.sh contains:

#!/bin/sh -uex
java -Ddb.host="${DB_HOST}" -jar /app.jar
Matt
  • 68,711
  • 7
  • 155
  • 158
0

As I understand you need to fetch parameters from config map and secret and set them as environment variables in your container. Furtunately it's quite nicely described in Kubernetes documentation.

Have a look at below links:

To sum up, such resources need to be just defined in Pod's configuration.