feco feco - 1 month ago 10x
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


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