<p>I am trying to initialize my container but I keep on getting <code>directory or file does not exist</code> error on the following script. I essentially need to get config files from repo into the folder.</p>
<p>I am not looking for alternative solutions by placing the exact file, I need this to be a solution for an arbitrary number of files.</p>
<p>Looking into the alpine docker, the <code>/usr/share</code> folder should exist.</p>
<p>This is the <code>initContainer</code> used:</p>
<pre class="lang-yaml prettyprint-override"><code>      initContainers:
        - name: init-config
          image: alpine/git
          command:
            - &quot;git clone https://github.com/coolacid/docker-misp.git /usr/repo &amp;&amp; cp -a /usr/repo/docker-misp/server-configs/ /usr/share&quot;
          volumeMounts:
            - mountPath: /usr/share
              name: misp-app-config
</code></pre>
<p>How do I properly move the files into a volume?</p>
<p>Edit 1: I am using the <code>alpine/git</code> image.</p>

Zerg Overmind
<p>First of all, I recommend using:</p>
<pre><code>command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
args: [&quot;git clone https://github.com/coolacid/docker-misp.git /usr/repo &amp;&amp; cp -a /usr/repo/server-configs/ /usr/share&quot;]
</code></pre>
<p>instead of:</p>
<pre><code>command:
            - &quot;git clone https://github.com/coolacid/docker-misp.git /usr/repo &amp;&amp; cp -a /usr/repo/docker-misp/server-configs/ /usr/share&quot;
        
</code></pre>
<p>Additionally, you shouldn't specify the <code>docker-misp</code> directory as all the contents of the <code>docker-misp.git</code> repository have been cloned  to <code>/usr/repo</code>:</p>
<pre><code># git clone https://github.com/coolacid/docker-misp.git /usr/repo
Cloning into '/usr/repo'...
remote: Enumerating objects: 905, done.
remote: Counting objects: 100% (160/160), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 905 (delta 144), reused 136 (delta 136), pack-reused 745
Receiving objects: 100% (905/905), 152.64 KiB | 2.50 MiB/s, done.
Resolving deltas: 100% (444/444), done.

# ls /usr/repo
LICENSE  README.md  build-docker-compose.yml  docker-compose.yml  examples  modules  server  server-configs
</code></pre>
<hr />
<p>I've prepared an example to illustrate how it works:<br />
<strong>NOTE:</strong> I used <a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir" rel="nofollow noreferrer">emptyDir</a> but you probably want to use a different <a href="https://kubernetes.io/docs/concepts/storage/volumes/#volume-types" rel="nofollow noreferrer">type of volumes</a>:</p>
<pre><code>$ cat app-1.yml
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: app-1
  name: app-1
spec:
  initContainers:
    - name: init-config
      image: alpine/git
      command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
      args: [&quot;git clone https://github.com/coolacid/docker-misp.git /usr/repo &amp;&amp; cp -a /usr/repo/server-configs/ /usr/share&quot;]
      volumeMounts:
        - mountPath: /usr/share
          name: misp-app-config
  containers:
  - image: nginx
    name: web-1
    volumeMounts:
    - mountPath: &quot;/work-dir&quot;
      name: misp-app-config
  volumes:
  - name: misp-app-config
    emptyDir: {}
    
$ kubectl apply -f app-1.yml
pod/app-1 created

$ kubectl get pods
NAME    READY   STATUS    RESTARTS   AGE
app-1   1/1     Running   0          11s
</code></pre>
<p>We can check if the <code>server-configs</code> directory has been copied to the <code>web-1</code> Pod:</p>
<pre><code>$ kubectl exec -it app-1 -- sh
Defaulted container &quot;web-1&quot; out of: web-1, init-config (init)
# ls /work-dir
server-configs
# ls /work-dir/server-configs
email.php
</code></pre>
<p>As you can see in the example above, everything works as expected.</p>
