I have a Docker image and I'd like to share an entire directory on a volume (a Persistent Volume) on Kubernetes.
FROM node:carbon
WORKDIR /node-test
COPY hello.md /node-test/hello.md
VOLUME /node-test
CMD ["tail", "-f", "/dev/null"]
Basically it copies a file hello.md
and makes it part of the image (lets call it my-image
).
On the Kubernetes deployment config I create a container from my-image
and I share a specific directory to a volume.
# ...
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
I'd expect to see the hello.md
file in the directory of the persistent volume, but nothing shows up.
If I don't bind the container to a volume I can see the hello.md
file (with kubectl exec -it my-container bash
).
I'm not doing anything different from what this official Kubernetes example does. As matter of fact I can change mountPath
and switch to the official Wordpress image and it works as expected.
How can Wordpress image copy all files into the volume directory?
What's in the Wordpress Dockerfile that is missing on mine?
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.
volumeMounts:
- name: node-volume
mountPath: /node-test/testdir
subPath: testdir
volumes:
- name: node-volume
persistentVolumeClaim:
claimName: node-volume-claim
you can find for more information here using-subpath