<p>I'm trying to copy the final WordPress files from the official WordPress Docker image, from an initContainer into an emptyDir volume. I expect the emptyDir volume to contain the entire WordPress installation so I can share this between containers. Instead I only get the wp-contents folder with no content. No other files or folders are copied over.</p>
<p>After reviewing the <a href="https://github.com/docker-library/wordpress/tree/b1127748deb2db34e9b1306489e24eb49720454f/php7.4/fpm-alpine" rel="nofollow noreferrer">WordPress Dockerfile and entrypoint</a>, I suspect the entrypoint is not getting executed because the Dockerfile has instructions to create the wp-content folder in /var/www/html, but it seems like nothing within the entrypoint is getting executed.</p>
<p>I have tried changing my <code>args:</code> to <code>args: [&quot;sh&quot;, &quot;-c&quot;, &quot;sleep 60 &amp;&amp; cp -r /var/www/html/. /shared-wordpress&quot;]</code> in hopes that the container just needed some time to finish running through the entrypoint before I run the <code>cp</code> command, but that has no effect. If you inspect the <code>/shared-wordpress</code> mount in the running wordpress container, it only shows the wp-content folder.</p>
<p>Copying the WordPress files from <code>/usr/src/wordpress</code> works great with the exception that it does NOT include the generated wp-config.php file. I need all the WordPress files along with the generated wp-config.php file.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:
      containers:
      - name: wordpress
        image: wordpress:5.5.1-php7.4-fpm-alpine
        volumeMounts:
        - name: shared-wordpress
          mountPath: /shared-wordpress
      initContainers:
      - name: init-wordpress
        image: wordpress:5.5.1-php7.4-fpm-alpine
        env:
        - name: WORDPRESS_DB_HOST
          value: test_host
        - name: WORDPRESS_DB_USER
          value: root
        - name: WORDPRESS_DB_PASSWORD
          value: hw8djdl21ds
        - name: WORDPRESS_DB_NAME
          value: local_wordpress
        - name: WORDPRESS_DEBUG
          value: &quot;1&quot;
        - name: WORDPRESS_CONFIG_EXTRA
          value: &quot;define( 'FS_METHOD', 'direct' );&quot;
        args: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;cp -r /var/www/html/. /shared-wordpress&quot;]
        volumeMounts:
        - name: shared-wordpress
          mountPath: /shared-wordpress
      volumes:
      - name: shared-wordpress
        emptyDir: {}
</code></pre>

<p>Your data is not being copied because your docker cmd is overwritten by <code>args</code> yaml field.</p>
<p>Docker entrypoint exec requires <code>php-fpm</code> to be passed as an further argument in order to trigger the code that generates the word press files.</p>
<p>After some testing i find a way to address your question.
It is a more workaround than solution but it solves your problem.</p>
<p>So to trigger code generation you have to set the first parameter to <code>php-fpm</code>. In the example below I'm using <code>-v</code> parameter so the programs exist immediately. If you don`t pass any arguments it would start and hold init container from exiting.</p>
<pre><code>initContainers:  
- args:  
   - php-fpm  
   - -v
</code></pre>
<p>Now the last part is tho address the issues with copying files. I have removed the <code>cp</code> args and mounted <code>EmptyDir</code>  into <code>/var/www/html</code>. Now the files are being generated directly to your desired volume so there no need to copying the files afterwards.</p>
<pre><code> initContainers:
   volumeMounts:
    - name: shared-wordpress
      mountPath: /var/www/html
</code></pre>
