<p>I have a spring boot application with two profiles, dev and prod, my docker file is:</p>

<pre><code>FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-Dspring.profiles.active=dev","-cp","app:app/lib/*","com.my.Application"]
</code></pre>

<p>please not that, when building the image,  I specify the entrypoint as command line argument.</p>

<p>This is the containers section of my kubernetes deployment where I use this image:</p>

<pre><code>containers:
  - name: myapp
    image: myregistry.azurecr.io/myapp:0.1.7
    imagePullPolicy: "Always"
    ports:
    - containerPort: 8080
      name: myapp
    readinessProbe:
      httpGet:
        path: /actuator/health
        port: 8080
      timeoutSeconds: 3
      periodSeconds: 20
      failureThreshold: 3
</code></pre>

<p>It works  but has a major flaw: how can I now switch to the production environment without rebuilding the image? </p>

<p>The best would be to remove that ENTRYPOINT in my docker file and give this configuration in my kubernetes yml so that I could always use the same image...is this possible?</p>

<p>edit: I saw that there is a lifecycle istruction but note that I have a readiness probe based on the spring boot's actuator. It would always fail if I used this construct.</p>

Phate
<p>You can override an image's <code>ENTRYPOINT</code> by using the <code>command</code> property of a Kubernetes Pod spec. Likewise, you could override <code>CMD</code> by using the <code>args</code> property (also see <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="nofollow noreferrer">the documentation</a>):</p>

<pre><code>containers:
- name: myapp
  image: myregistry.azurecr.io/myapp:0.1.7
  imagePullPolicy: "Always"
  command: ["java","-Dspring.profiles.active=prod","-cp","app:app/lib/*","com.my.Application"]
  ports:
  - containerPort: 8080
    name: myapp
</code></pre>

<p>Alternatively, to provide a higher level of abstraction, you might write your own entrypoint script that reads the application profile from an environment variable:</p>

<pre><code>#!/bin/sh

PROFILE="${APPLICATION_CONTEXT:-dev}"
exec java "-Dspring.profiles.active=$PROFILE" -cp app:app/lib/* com.my.Application
</code></pre>

<p>Then, you could simply pass that environment variable into your pod:</p>

<pre><code>containers:
- name: myapp
  image: myregistry.azurecr.io/myapp:0.1.7
  imagePullPolicy: "Always"
  env:
  - name: APPLICATION_CONTEXT
    value: prod
  ports:
  - containerPort: 8080
    name: myapp
</code></pre>
