<p>I have a container image that already has the <code>index.html</code> file. My goal is to pick that <code>index.html</code> update it (using simple placeholder replacement) and then put it back.</p>
<p>I am trying to use the <code>initContainer</code> for the same. But somehow it's not working out for me.</p>
<p>Here is what I have tried in <code>deployment.yaml</code></p>
<pre><code> initContainers:
        - name: init-container
          image: &quot;my-image-name&quot;
          command: [&quot;/bin/sh&quot;, &quot;-c&quot;]
          args:
            - cp /usr/share/nginx/html/index.html /tmp/index.html
            - sed -i 's#&lt;base href=&quot;./&quot;&gt;#&lt;base href=&quot;/my-base/&quot;&gt;#' /tmp/index.html
            - cp /tmp/index.html /usr/share/nginx/html/index.html
          volumeMounts:
          - name: custom-index
            mountPath: /usr/share/nginx/html/

containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: &quot;my-image-name&quot;
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          volumeMounts:
          - mountPath: /usr/share/nginx/html/
            name: custom-index

volumes:
        - emptyDir: {}
          name: custom-index
</code></pre>
<p>However with above, I am getting the following error:</p>
<pre><code>Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting &quot;/var/lib/kubelet/pods/bb343f44-00eb-477b-9e26-17949a73100d/volume-subpaths/custom-index/my-container-name/7&quot; to rootfs at &quot;/usr/share/nginx/html/&quot;: mount /var/lib/kubelet/pods/bb343f44-00eb-477b-9e26-17949a73100d/volume-subpaths/custom-index/my-container-name/7:/usr/share/nginx/html/ (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown

</code></pre>
<p>How to achieve this?</p>
<p>Please note that I cannot maintain the separate copy of <code>index.html</code>, I need to use the one present in the main container, update it and put it back.</p>

Kalpesh Patel
<p>For initcontainer can you please check with below. If required correct the sed statement</p>
<pre><code> command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;cp /usr/share/nginx/html/index.html /remoteDir &amp;&amp; sed -i 's#&lt;base href=\&quot;./\&quot;&gt;#&lt;base href=\&quot;/my-base/\&quot;&gt;#' /remoteDir/index.html&quot;]
 volumeMounts:
 - name: custom-index
   mountPath: /remoteDir
</code></pre>
