<p>i'm launching a glassfish pod on my Kubernetes cluster, and i'm trying to copy some .war files from a folder that's on my host, but the command cp always seems to fail.</p>

<p>my yaml file:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
 name: glassfish
spec:
# replicas: 2
 selector:
  matchLabels:
   app: glassfish
 strategy:
  type: Recreate
 template:
  metadata:
   labels:
    app: glassfish
  spec:
   containers:
   - image: glassfish:latest
     name: glassfish
     ports:
     - containerPort: 8080
       name: glassfishhttp
     - containerPort: 4848
       name: glassfishadmin
     command: ["/bin/cp"]
     args: #["/mnt/apps/*","/usr/local/glassfish4/glassfish/domains/domain1/autodeploy/"]
     - /mnt/apps/
     - /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/
     volumeMounts:
     - name: glassfish-persistent-storage
       mountPath: /mount
     - name: app
       mountPath: /mnt/apps
   volumes:
   - name: glassfish-persistent-storage
     persistentVolumeClaim:
      claimName: fish-mysql-pvc
   - name: app
     hostPath:
      path: /mnt/nfs
      type: Directory</code></pre>
</div>
</div>
</p>

<p>I'm trying to use the following command in my container:</p>

<pre><code>cp /mnt/apps/* /usr/local/glassfish4/glassfish/domains/domain1/autodeploy
</code></pre>

<p>What am I doing wrong?</p>

<p>So far i've tried to do it with the /<em>, without it, using /*
When i use apps/</em> i see "item or directory not found", when i use apps/ i get "directory ommitted", i need only whats in the map, not the map itself so -r doesn't really help either.</p>

<p>Two things to note here:</p>

<ol>
<li>If you want to copy a direcyory using <code>cp</code>, you have to provide the <code>-a</code> or <code>-R</code> flag to <code>cp</code>:</li>
</ol>

<blockquote>
<pre><code> -R    If source_file designates a directory, cp copies the directory and the entire subtree connected at
       that point.  If the source_file ends in a /, the contents of the directory are copied rather than
       the directory itself.  This option also causes symbolic links to be copied, rather than indirected
       through, and for cp to create special files rather than copying them as normal files.  Created
       directories have the same mode as the corresponding source directory, unmodified by the process'
       umask.

       In -R mode, cp will continue copying even if errors are detected.
</code></pre>
</blockquote>

<ol start="2">
<li><p>If you use <code>/bin/cp</code> as your entrypoint in the pod, then this command is not executed in a shell. The <code>*</code> in <code>/path/to/*</code> however is a shell feature.</p></li>
<li><p>initContainers do not have <code>args</code>, only `command.</p></li>
</ol>

<p>To make this work, use <code>/bin/sh</code> as the command instead:</p>

<pre><code>command:
  - /bin/sh
  - -c
  - cp /mnt/apps/* /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/
</code></pre>
