title: Delete environmental variable from docker image
body: <p>I have looked around online and tried the obvious route (explained below) to remove an environmental variable from a docker image.</p>
  
  <p>1 - I create a container from a modified ubuntu image using:</p>
  
  <p><code>docker run -it --name my_container my_image</code></p>
  
  <p>2 - I inspect the image and see the two environmental variables that I want to remove using:</p>
  
  <p><code>docker inspect my_container</code></p>
  
  <p>which yields:</p>
  
  <pre><code>...
      "Env": [
          "env_variable_1=abcdef",
          "env_variable_2=ghijkl",
          "env_variable_3=mnopqr",
  ...
  </code></pre>
  
  <p>3 - I exec into the container and remove the environmental variables via:</p>
  
  <pre><code>docker exec -it my_container bash
  unset env_variable_1
  unset env_variable_2
  </code></pre>
  
  <p>4 - I check to make sure the specified variables are gone:</p>
  
  <pre><code>docker inspect my_container
  </code></pre>
  
  <p>which yields:</p>
  
  <pre><code>...
      "Env": [
          "env_variable_3=mnopqr",
  ...
  </code></pre>
  
  <p>5 - I then commit this modified container as an image via:</p>
  
  <p><code>docker commit my_container my_new_image</code></p>
  
  <p>6 - And check for the presence of the deleted environmental variables via:</p>
  
  <pre><code>docker run -it --name my_new_container my_new_image
  docker inspect my_new_container
  </code></pre>
  
  <p>which yields (drumroll please):</p>
  
  <pre><code>...
      "Env": [
          "env_variable_1=abcdef",
          "env_variable_2=ghijkl",
          "env_variable_3=mnopqr",
  ...
  </code></pre>
  
  <p>AKA the deleted variables are not carried through from the modified container to the new image in the <code>docker commit</code></p>
  
  <p>What am I missing out on here? Is <code>unset</code> really deleting the variables? Should I use another method to remove these environmental variables or another/modified method to commit the container as an image?</p>
  
  <p>PS: I've confirmed the variables first exist when inside the container via <code>env</code>. I then confirmed they were not active using the same method after using <code>unset my_variable</code></p>
  
  <p>Thanks for your help!</p>