<p>I have two containers inside my Pod:</p>

<ul>
<li>Container A based on my own Dockerfile. Inside this Dockerfile, there is  <code>COPY ./files /my-files</code> command. This image is inside my GitLab Docker registry.</li>
<li>Container B based on image from hub.docker.com.</li>
</ul>

<p>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 <code>volume</code> (it's not a persisted data) inside this pod and <code>volumeMounts</code> to the container.</p>

<p>Unfortunately when I add <code>volumeMounts</code> to Container A with <code>mountPath: /my-files</code> this directory is emptied and there are no files that were added when an image was created.</p>

<p>What should I do to keep this data and share it with Container B.</p>

<p>This is part of my Deployment.yaml file:</p>

<pre><code>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: {}
</code></pre>

<p>A ugly hack, use init container, to copy data into emptyDir volume, then mount volume in 2nd container.</p>

<pre><code>  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: {}
</code></pre>
