title: How to pass Java options/variables to Springboot app in docker run command
body: <p>I have a Spring Boot application which uses profiles to configure in different environments. I want to pass this profile information as a parameter to my <code>docker run</code> command. How do I go about doing it?</p>
  
  <p>Here is my dockerfile</p>
  
  <pre><code>FROM openjdk:8-jdk-alpine
  ARG JAR_FILE=target/demo-app-1.0-SNAPSHOT.jar
  
  COPY ${JAR_FILE} /opt/lib/demo-app.jar
  
  EXPOSE 80
  
  # ENTRYPOINT ["java","-Dspring.profiles.active=dockerdev","-jar","/opt/lib/demo-app.jar"]
  # Above line works, but not desired as profile will change in diff envs
  ENTRYPOINT ["java","-jar","/opt/lib/demo-app.jar"]
  </code></pre>
  
  <p>I have tried the following, but, none works</p>
  
  <p><code>docker run -p 8000:80 demo-app -Dspring.profiles.active=dockerdev</code></p>
  
  <p><code>docker run -p 8000:80 demo-app --rm -e JAVA_OPTS='-Dspring.profiles.active=dockerdev'</code></p>
  
  <p>Please help.</p>
  
  <p><strong>Clarification:</strong> I am using multiple profiles. Hence I do not want the active profile to be mentioned within the application or the docker file. Instead, I want to use the same application and docker file and run it in different environments, and pass the active profile to be used in the docker run command. Apologies if anything above did not clarify that.</p>