<p>I have a Docker image and I'd like to share an entire directory on a volume (a Persistent Volume) on Kubernetes.</p>

<h3>Dockerfile</h3>

<pre><code>FROM node:carbon
WORKDIR /node-test
COPY hello.md /node-test/hello.md
VOLUME /node-test
CMD ["tail", "-f", "/dev/null"]
</code></pre>

<p>Basically it copies a file <code>hello.md</code> and makes it part of the image (lets call it <code>my-image</code>).</p>

<p>On the Kubernetes deployment config I create a container from <code>my-image</code> and I share a specific directory to a volume.</p>

<h3>Kubernetes deployment</h3>

<pre><code># ...
 spec:
    containers:
    - image: my-user/my-image:v0.0.1
      name: node
      volumeMounts:
      - name: node-volume
        mountPath: /node-test
    volumes:
    - name: node-volume
      persistentVolumeClaim:
        claimName: node-volume-claim
</code></pre>

<p>I'd expect to see the <code>hello.md</code> file in the directory of the persistent volume, but nothing shows up.</p>

<p>If I don't bind the container to a volume I can see the <code>hello.md</code> file (with <code>kubectl exec -it my-container bash</code>).</p>

<p>I'm not doing anything different from what this <a href="https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/" rel="nofollow noreferrer">official Kubernetes example</a> does. As matter of fact I can change <code>mountPath</code> and switch to the official Wordpress image and it works as expected. </p>

<p>How can <a href="https://hub.docker.com/_/wordpress" rel="nofollow noreferrer">Wordpress image</a> copy all  files into the volume directory?</p>

<p>What's in the Wordpress Dockerfile that is missing on mine?</p>

a.barbieri
<p>In order not to overwrite the existing files/content, you can use subpath to mount the testdir directory (In the example below)   in the existing Container file system.  </p>

<pre><code> volumeMounts:
  - name: node-volume
    mountPath: /node-test/testdir
    subPath: testdir
volumes:
- name: node-volume
  persistentVolumeClaim:
    claimName: node-volume-claim
</code></pre>

<p>you can find for more information here <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer">using-subpath</a></p>
