<p>Here's what my Dockerfile looks like for an image I'm creating.</p>

<pre><code>FROM python:3.7-alpine
COPY requirements.txt /
RUN pip install -r /requirements.txt
ENV U_PATH="a"
WORKDIR $U_PATH
</code></pre>

<p>I override the env variable <code>U_PATH</code> when I call it using <code>docker run -it -e U_PATH=/mnt temp:v1 /bin/sh</code> but the <code>WORKDIR</code> is set during build time and I cannot change that during runtime.</p>

<p>Is there any way to dynamically set the working directory at runtime by passing an env variable?</p>

<p>While not an environment variable, don't forget you can alter the working directory of a Pod's container via the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#container-v1-core" rel="nofollow noreferrer"><code>workingDir:</code> PodSpec field</a></p>

<pre><code>containers:
- name: foo
  image: 'temp:v1'
  workingDir: /mnt
</code></pre>
