<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Docker on Everyone Has a Story</title><link>https://bhaveshsgupta.com/tags/docker/</link><description>Recent content in Docker on Everyone Has a Story</description><generator>Hugo</generator><language>en-us</language><managingEditor>BhaveshSGupta@gmail.com (Bhavesh S. Gupta)</managingEditor><webMaster>BhaveshSGupta@gmail.com (Bhavesh S. Gupta)</webMaster><lastBuildDate>Thu, 26 Nov 2026 15:43:04 +0530</lastBuildDate><atom:link href="https://bhaveshsgupta.com/tags/docker/index.xml" rel="self" type="application/rss+xml"/><item><title>Changing an environment variable in a running Docker container</title><link>https://bhaveshsgupta.com/blog/changing-an-environment-variable-in-a-running-docker-container/</link><pubDate>Thu, 26 Nov 2026 09:00:00 +0530</pubDate><author>BhaveshSGupta@gmail.com (Bhavesh S. Gupta)</author><guid>https://bhaveshsgupta.com/blog/changing-an-environment-variable-in-a-running-docker-container/</guid><description>&lt;p&gt;We recently moved a Node.js app from Node 14 to Node 24, and as part of that added one line to its Dockerfile:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt" id="hl-0-1"&gt;&lt;a class="lnlinks" href="#hl-0-1"&gt;1&lt;/a&gt;&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-dockerfile" data-lang="dockerfile"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;NODE_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;production&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;Our production environment had never set &lt;code&gt;NODE_ENV&lt;/code&gt;. Express caches compiled views when it&amp;rsquo;s &lt;code&gt;production&lt;/code&gt;, so we wanted it set, and we knew that setting it would change more than Express. This line decides which queue PDF uploads go to:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt" id="hl-1-1"&gt;&lt;a class="lnlinks" href="#hl-1-1"&gt;1&lt;/a&gt;&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-js" data-lang="js"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;process_pdf_&amp;#34;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NODE_ENV&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s2"&gt;&amp;#34;development&amp;#34;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;When someone uploads a PDF, the app puts a job on a queue, and a separate worker container converts it to slides. With &lt;code&gt;NODE_ENV&lt;/code&gt; unset, production had always created &lt;code&gt;process_pdf_development&lt;/code&gt; jobs, and the worker on the production server was set up to match:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;div class="chroma"&gt;&#10;&lt;table class="lntable"&gt;&lt;tr&gt;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code&gt;&lt;span class="lnt" id="hl-2-1"&gt;&lt;a class="lnlinks" href="#hl-2-1"&gt;1&lt;/a&gt;&#10;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&#10;&lt;td class="lntd"&gt;&#10;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;JOB_TYPE=process_pdf_development&#10;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&#10;&lt;/div&gt;&#10;&lt;/div&gt;&lt;p&gt;Once the new image was live, the app would create &lt;code&gt;process_pdf_production&lt;/code&gt; jobs, and the worker would ignore them until it was told to look for that type too. So changing the worker&amp;rsquo;s &lt;code&gt;JOB_TYPE&lt;/code&gt; was part of the upgrade plan. The worker was already running, though, and Docker won&amp;rsquo;t change a running container&amp;rsquo;s environment.&lt;/p&gt;&#10;&lt;p&gt;You have to recreate the container. Dump its current environment to a file, edit the one line, and create a new container from the same image with &lt;code&gt;--env-file&lt;/code&gt;. Rename the old container first instead of deleting it, so rolling back takes one command.&lt;/p&gt;</description></item></channel></rss>