I have two containers inside my Pod:
COPY ./files /my-files
command. This image is inside my GitLab Docker registry.I'd like to share data from Container A that are stored inside /my-files to Container B. I thought that I need to create a volume
(it's not a persisted data) inside this pod and volumeMounts
to the container.
Unfortunately when I add volumeMounts
to Container A with mountPath: /my-files
this directory is emptied and there are no files that were added when an image was created.
What should I do to keep this data and share it with Container B.
This is part of my Deployment.yaml file:
containers:
- name: Container-A
image: "my-gitlab-registry/my-image-a-with-copied-files"
volumeMounts:
- name: shared-data
mountPath: /my-files
- name: Container-B
image: "some-public-image"
volumeMounts:
- name: shared-data
mountPath: /files-from-container-a
volumes:
- name: shared-data
emptyDir: {}
A ugly hack, use init container, to copy data into emptyDir volume, then mount volume in 2nd container.
initContainers:
- name: init-config-data-copy-wait
image: datacontainer
command:
- sh
- "-ce"
- |
set -ex
cp -r /src-data/* /dst-data/
ls /dst-data/
volumeMounts:
- mountPath: /dst-data
name: dst-data-volume
volumes:
- name: dst-data-volume
emptyDir: {}