feco feco - 1 year ago 1195
Java Question

How to pass System property to docker containers?

So I know you can pass Environment variables to a docker container using -e like:

docker run -it -e "var=var1" myDockerImage

But I need to pass a System Property to a docker container, because this is how I run my JAR:

java -Denviroment=dev -jar myjar.jar

So how can I pass a -D System property in Docker? Like:

docker run -it {INSERT Denviroment here} myDockerImage

Answer Source

Use the variable you passed into the container on the java command:

docker run -it -e "ENV=dev" myDockerImage
java -Denvironment=$ENV -jar myjar.jar
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download