<p>I have a .bat file right now that runs a docker command with </p>

<pre><code>docker run --rm -it --env-file .env --name my-name my-name /bin/sh -c "mvn test -Dtest=my.runner.Runner"
</code></pre>

<p>I have a k8s config-map.yml and a deployment.yml with a configMapRef to replace the <strong>.env</strong> file, but I don’t know how to reference it in my docker run command. </p>

<p>It should work that every time I deploy the image from my docker registry , it picks up the config-map and uses that for the repos envs. </p>

user6754289
<p>If you try to set the value of an environment variable from <strong>inside a RUN statement</strong> like <code>RUN export VARI=5 &amp;&amp; ...</code>, you won’t have access to it in any of the next RUN statements. The reason for this, is that for each RUN statement, a new container is launched from an intermediate image. An image is saved by the end of the command, but environment variables do not persist that way.</p>

<p>So firstly you should make changes in your image, build it and then change its reference in deployment.yaml. After wole process just execute configmap and  deployment. Now everything should works fine. Trying to combine this process (docker run)with Kubernetes components it is not good approach.</p>

<p>Useful article: <a href="https://vsupalov.com/docker-arg-env-variable-guide/" rel="nofollow noreferrer">docker-arg-env</a>.</p>

<p>Overall documentation: <a href="https://docs.docker.com/engine/reference/commandline/run/" rel="nofollow noreferrer">docker-run</a>.</p>
