Passing env variables to DOCKER Spring Boot Passing env variables to DOCKER Spring Boot docker docker

Passing env variables to DOCKER Spring Boot


The easiest (and probably the best way) to do it via environment variable in a docker container:

SPRING_PROFILES_ACTIVE=dev,swagger

UPDATE:

In order to set environment variables to docker, you do not need to modify Dockerfile. Just build your docker image and then run it with the env variables set:

docker run your-docker-container -e SPRING_PROFILES_ACTIVE='dev,swagger' -p 8080:8080


In the .Dockerfile file:

ENTRYPOINT [ "sh", "-c", "java -Dspring.profiles.active=**${ENV}** -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

And while running the docker:

docker run --env ENV=*local* -d -p 8080:8080 <*image id*>

This way, the environment variable gets local as value and passes to Dockerfile when we bring up a container.

Update

You can also do like

ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=${ENV} -Djava.security.egd=file:/dev/./urandom","app.jar"]

and while docker image

docker run --env ENV=local -d -p 8080:8080 <*image id*>