<p>I have a deployment that runs two containers. One of the containers attempts to build (during deployment) a javascript bundle that the other container, nginx, tries to serve.</p>
<p>I want to use a shared volume to place the javascript bundle after it's built.</p>
<p>So far, I have the following deployment file (with irrelevant pieces removed):</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      hostNetwork: true
      containers:
      - name: personal-site
        image: wheresmycookie/personal-site:3.1
        volumeMounts:
        - name: build-volume
          mountPath: /var/app/dist
      - name: nginx-server
        image: nginx:1.19.0
        volumeMounts:
        - name: build-volume
          mountPath: /var/app/dist
      volumes:
      - name: build-volume
        emptyDir: {}
</code></pre>
<p>To the best of my ability, I have followed these guides:</p>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/#emptydir</a></li>
<li><a href="https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/</a></li>
</ul>
<p>One other things to point out is that I'm trying to run this locally atm using <code>minikube</code>.</p>
<p>EDIT: The Dockerfile I used to build this image is:</p>
<pre><code>FROM node:alpine
WORKDIR /var/app

COPY . .
RUN npm install
RUN npm install -g @vue/cli@latest

CMD [&quot;npm&quot;, &quot;run&quot;, &quot;build&quot;]
</code></pre>
<p>I realize that I do not need to build this when I actually run the image, but my next goal is to insert pod instance information as environment variables, so with javascript unfortunately I can only build once that information is available to me.</p>
<h2>Problem</h2>
<p>The logs from the <code>personal-site</code> container reveal:</p>
<pre><code>-  Building for production...
 ERROR  Error: EBUSY: resource busy or locked, rmdir '/var/app/dist'
 Error: EBUSY: resource busy or locked, rmdir '/var/app/dist'
</code></pre>
<p>I'm not sure why the build is trying to remove <code>/dist</code>, but also have a feeling that this is irrelevant. I could be wrong?</p>
<p>I thought that maybe this could be related to the lifecycle of containers/volumes, but the docs suggest that &quot;An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node&quot;.</p>
<h2>Question</h2>
<p>What are some reasons that a volume might not be available to me after the containers are already running? Given that you probably have much more experience than I do with Kubernetes, what would you look into next?</p>

wheresmycookie
<p>The best way is to customize your image's entrypoint as following:</p>
<ul>
<li><p>Once you finish building the <code>/var/app/dist</code> folder, copy(or move) this folder to another empty path (.e.g: <code>/opt/dist</code>)</p>
<pre><code>cp -r /var/app/dist/* /opt/dist
</code></pre>
</li>
</ul>
<p>PAY ATTENTION: this Step must be done in the script of ENTRYPOINT not in the RUN layer.</p>
<ul>
<li><p>Now use <code>/opt/dist</code> instead..:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  ...
spec:
  ...
  template:
    ...
    spec:
      hostNetwork: true
      containers:
      - name: personal-site
        image: wheresmycookie/personal-site:3.1
        volumeMounts:
        - name: build-volume
          mountPath: /opt/dist # &lt;--- make it consistent with image's entrypoint algorithm
      - name: nginx-server
        image: nginx:1.19.0
        volumeMounts:
        - name: build-volume
          mountPath: /var/app/dist

      volumes:
      - name: build-volume
        emptyDir: {}
</code></pre>
</li>
</ul>
<p>Good luck!</p>
<p>If it's not clear how to customize the entrypoint, share with us your entrypoint of the image and we will implement it.</p>
