title: Kubernetes share volume between containers inside a Deployment
body: <p>Before posting this question I followed this answer <a href="https://stackoverflow.com/questions/30538210/how-to-mimic-volumes-from-in-kubernetes">How to mimic &#39;--volumes-from&#39; in Kubernetes</a> but it didn't work for me.</p>
  
  <p>I have 2 containers:</p>
  
  <ul>
  <li><strong>node</strong>: its image contains all the files related to the app ( inside <code>/var/www</code> ) </li>
  <li><strong>nginx</strong>: it needs to access the files inside the <strong>node</strong> image (especially the <code>/clientBuild</code> folder where I have all the assets)</li>
  </ul>
  
  <p>What is inside the <strong>node</strong> image:</p>
  
  <pre><code>$ docker run node ls -l
  &gt; clientBuild/
  &gt; package.json
  &gt; ...
  </code></pre>
  
  <p>A part of the <code>nginx.prod.conf</code>:</p>
  
  <pre><code>location ~* \.(jpeg|jpg|gif|png|ico|css|js|gz|map|json)$ {
    include /etc/nginx/mime.types;
    root /usr/local/nginx/html/clientBuild/;
  }
  </code></pre>
  
  <p>And the the deployment setup:</p>
  
  <pre><code>kind: Deployment
  apiVersion: extensions/v1beta1
  metadata:
    name: pwa-app-production
    labels:
      app: MyApp
  spec:
    replicas: 1
    template:
      metadata:
        name: app
        labels:
          app: MyApp
          env: production
      spec:
        containers:
        - name: nginx
          image: nginx
          command: [nginx, -c, /nginx.prod.conf, -g, 'daemon off;']
          resources:
            limits:
              memory: "500Mi"
              cpu: "100m"
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /usr/local/nginx/html
              name: pwa-disk
              readOnly: true
          ports:
          - name: nginx
            containerPort: 80
        initContainers:
        - name: node
          image: node
          command: [npm, start]
          resources:
            limits:
              memory: "500Mi"
              cpu: "100m"
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /var/www
              name: pwa-disk
          ports:
          - name: app
            containerPort: 3000
          - name: api
            containerPort: 3001
        volumes:
          - name: pwa-disk
            emptyDir: {}
  </code></pre>
  
  <p>I first attempt to put both images in the same <code>containers</code> key, but i got: <code>/var/www/package.json not found</code> on <code>npm start</code></p>
  
  <p>Then I moved it inside the <code>initContainers</code> but now I only have a notice that it failed, but it does not tell me why. View logs does not show any details too.</p>
  
  <p>Notice that when I remove volume part, the <code>npm start</code> works.</p>
  
  <p><a href="https://i.stack.imgur.com/Susmc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Susmc.png" alt="enter image description here"></a></p>