-2

I created a docker file like this

ARG ENV
FROM openjdk:11-jdk
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","-Dspring.profiles.active=${ENV}", "app.jar"]

while doing docker run -p 8100:8080 anupbiswas1984/docker-env --e ENV=test

it is not identifying ${ENV}

How can I pass the ENV as an argument during "docker run..."

DreamBold
  • 2,727
  • 1
  • 9
  • 24
  • `ENV` (for an `ARG`) is no good identifier in docker .. – xerx593 Nov 29 '22 at 20:30
  • Does this answer your question? [How to pass ARG value to ENTRYPOINT?](https://stackoverflow.com/questions/34324277/how-to-pass-arg-value-to-entrypoint) – xerx593 Nov 29 '22 at 20:30

1 Answers1

2

Get rid of the ARG thing, as it's not needed and you aren't using it correctly anyway. Per the documentation:

The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command

So ARG is a build-time thing, and you are trying to use it as a run-time environment variable.

Also, you can get rid of the "-Dspring.profiles.active=${ENV}" part of your ENTRYPOINT because Spring Boot already looks for an environment variable named SPRING_PROFILES_ACTIVE so there's no need to define another thing here, and you're also introducing an issue with the way you are trying to resolve the ENV variable here.

FROM openjdk:11-jdk
COPY target/*.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

Then run it with:

docker run -e SPRING_PROFILES_ACTIVE=test -p 8100:8080 anupbiswas1984/docker-env
Mark B
  • 183,023
  • 24
  • 297
  • 295