<p>I build a Docker Image and use <code>COPY xyz.sh /bin/</code>
The <em>xyz.sh</em> file contains 1000+ lines of code and one of the line is <strong>Host:xyz.com</strong>
I used this Image in K8s. Now I want to change the <strong>Host</strong> Value in xyz.sh file.</p>

<ul>
<li><p>I don't want to Create a ConfigMap of full xyz.sh file and replace
that value with the new host. </p></li>
<li><p>I don't want to create a new Docker Image.</p></li>
</ul>

<p><strong><em>Question.</em></strong></p>

<p><strong>I there any way to Update only one line or word from ton on lines with the help of configmap or another way?</strong></p>

Ankit Singh
<h2>Reuse existing container image</h2>

<p>A simple solution is using a configmap to alter such <code>xyz.sh</code> like:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: new-entrypoint
data:
  new_entrypoint.sh: |
    #!/bin/bash
    sed -i 's/Host:xyz\.com/Host:abc.io/' /path/to/xyz.sh
    exec &lt;your-original-entrypoint.sh&gt; "$@"
</code></pre>

<p>Then mount this new configmap and use the file <code>new_entrypoint.sh</code> in <code>command</code> attribute.</p>

<p>This is ugly but you don't need to maintain 1k+ lines of bash script into a configmap.</p>

<p><strong>Notice</strong>: this may not work if your <code>xyz.sh</code> doesn't belong to current user/group that runs your container. Also it violate the idea of <em>immutable infrastructure</em>. So you will need to replace the <code>xyn.sh</code> via a configmap entry.</p>

<h2>From scratch</h2>

<p>So the line <code>Host:xyz.com</code> becomes configuration that you want to change at runtime. so you may want to alter such hard coded value into environment variable so that it can be override at runtime.</p>

<p>E.g., in your <code>xyz.sh</code>:</p>

<pre><code>MY_HOST=${MY_HOST:-"xyz.com"}
</code></pre>

<p>In dockerfile:</p>

<pre><code>ENV MY_HOST="default_host_for_your_docker_image".
</code></pre>

<p>In k8s pod description, you can do:</p>

<pre><code>containers:
  - name: xyz
    image: "your-docker-image-name"
    env:
    - name: MY_HOST
      value: abc.io
</code></pre>

<p>See <a href="https://12factor.net/config" rel="nofollow noreferrer">section III. Config of the 12-factor app</a>:</p>

<blockquote>
  <p>Store config in the environment</p>
</blockquote>
