title: Trying to get env args from openshift config into Dockerfile and then into nginx config using envsubst
body: <p>So I'm deploying a React app into Openshift that will call a separate API service and I need to determine the proxy_pass in my nginx.conf based on the staging environment- dev or prod. This seems to be a common enough use case but seems to be extremely difficult to implement. I'm using the nginxinc/nginx-unprivileged for my nginx server and not the regular nginx image though- I don't know if that's causing any issues. It seems to be using nginx 1.19 which supports envsubst in nginx.conf files.</p>
  <p>What I'm trying to do is this:</p>
  <ol>
  <li>Define a proxy_url environment variable in my buildConfig.yml and prodBuildConfig.yml respectively</li>
  <li>Fire off envsubst in my Dockerfile to replace the variables in my nginx.conf to pass into proxy_pass</li>
  </ol>
  <p>The code looks like this</p>
  <p>buildConfig.yml</p>
  <pre><code>...
    spec:
    resources: {}
    strategy:
      dockerStrategy:
        env:
          - name: &quot;API_URL&quot;
            value: &quot;http://devservice:8080&quot;
        dockerfilePath: Dockerfile
  </code></pre>
  <p>Dockerfile</p>
  <pre><code>...
  CMD /bin/bash -c &quot;envsubst '\$API_URL' &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; nginx -g 'daemon off;'&quot;
  
  </code></pre>
  <p>and finally the nginx.conf</p>
  <pre><code>...
  location /api {
      proxy_pass ${API_URL};
  }
  </code></pre>
  <p>But nothing seems to work. I've tried a million variations of the CMD bin/sh envsubst command like</p>
  <pre><code>CMD /bin/sh -c envsubst \${API_URL} &lt; /etc/nginx/conf.d/default.template &gt; /etc/nginx/conf.d/default.conf &amp;&amp; nginx -g 'daemon off;'
  
  </code></pre>
  <p>I've tried changing the quotes around as I've seen done on many posts, I've tried using bin/sh vs bin/bash, I've tried changing the name of the conf file to things like nginx.conf.template or just default.temp, I've tried copying the nginx template into the etc/nginx/templates folder which supposedly should automatically run envsubst and place it into /conf.d/ but that doesn't work. I've essentially tried it all. I'm completely new to Openshift, Docker, and Nginx so I really don't know what this workflow should even look like and whether or not I'm overcomplicating things or just on the wrong path all together. What am I missing? Please be as explicit as you can with how you explain things because I'm new to these technologies.</p>