<p>I have created a custom <strong>alpine</strong> image (alpine-audit) which includes a <em>jar</em> file in the <em><strong>/tmp</strong></em> directory. What I need is to use that alpine-audit image as the <strong>initContainers</strong> base image and copy that <em>jar</em> file that I've included, to a location where the Pod container can access.</p>
<p>My yaml file is like below</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: init-demo
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  initContainers:
  - name: install
    image: my.private-artifactory.com/audit/alpine-audit:0.1.0
    command: ['cp', '/tmp/auditlogger-1.0.0.jar', 'auditlogger-1.0.0.jar']
    volumeMounts:
    - name: workdir
      mountPath: &quot;/tmp&quot;
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}
</code></pre>
<p>I think there is some mistake in the <code>command</code> line.
I assumed <em>initContainer</em> copy that jar file to <em>emptyDir</em> then the nginx based container can access that jar file using the <em>mountPath</em>.
But it does not even create the Pod. Can someone point me where it has gone wrong?</p>

AnujAroshA
<p>When you are mouting a volume to a directory in pod, that directory have only content of the volume. If you are mounting <code>emptyDir</code> into your <code>alpine-audit:0.1.0</code> the /tmp directory becomes empty. I would mount that volume on some other dir, like <code>/app</code>, then copy the <code>.jar</code> from /tmp to /app.</p>
<p>The container is not starting probably because the initContainer failes running  the command.</p>
<p>Try this configuration:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
metadata:
  name: init-demo
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  initContainers:
  - name: install
    image: my.private-artifactory.com/audit/alpine-audit:0.1.0
    command: ['cp', '/tmp/auditlogger-1.0.0.jar', '/app/auditlogger-1.0.0.jar'] # &lt;--- copy from /tmp to new mounted EmptyDir
    volumeMounts:
    - name: workdir
      mountPath: &quot;/app&quot; # &lt;-- change the mount path not to overwrite your .jar
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}
</code></pre>
