<p>I have node(node:10) Dockerfile with custom package-lock.json , package.json , So using this dockerfile I need to create a dockerimage and then i want to run kubernetes job (kind:job) as one time task means if task is over your pod will be killed and also need to mount the output of /usr/src/app/ and /usr/src/app/node_modules to my kubernetes host path to serve the static content.</p>

<p>Dockerfile:-</p>

<pre><code>FROM node:10
WORKDIR /usr/src/app/
#COPY package*.json /usr/src/app/
COPY . /usr/src/app/
RUN npm install
</code></pre>

<p>File which are already availble in Dockerfile directory: -</p>

<pre><code>Dockerfile  README.md  codegen.yml  package-lock.json  package.json  public  src  tsconfig.json
</code></pre>

<p>Kubernetes job file:-</p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: workspace-forntend
spec:
  template:
    metadata:
      name: workspace-forntend
    spec:
      containers:
      - name: workspace-forntend
        image: node:10 (dummy path for public post) 
        imagePullPolicy: IfNotPresent
        command: ["/bin/bash","-c"]
        args: ["npm run build"]
        volumeMounts:
          - name: mount-1
            mountPath: /usr/src/app/
          - name: mount-2
            mountPath: /usr/src/app/node_modules
      volumes:
          - name: mount-1
            hostPath:
              path: /root/mount-1
              type: DirectoryOrCreate
          - name: mount-2
            hostPath:
               path: /root/mount-2
               type: DirectoryOrCreate
      restartPolicy: Never
</code></pre>

<p>But getting error:- </p>

<pre><code>npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /usr/src/app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
</code></pre>

<p>Note :- all the permission (777), path /usr/src/app (pwd), user (root) are intact.</p>

me25
<p>Since you've <code>COPY</code>ed your application code into your Docker image, you don't need to separately mount it in your job specification.  Delete the <code>volumes:</code> and <code>volumeMounts:</code> sections from the job spec.  You'll also need to change the <code>image:</code> to point at the image you built out of that Dockerfile, pushed to some Docker registry.</p>

<p>Kubernetes is especially unsuited for a live development environment.  <code>hostPath</code> volumes are really sort of an escape hatch around the normal Kubernetes storage system and not a normal way to maintain storage or external content.  In addition to putting your application code in an image as you've shown it, you also will need to manually copy the application to every node in the cluster.  This breaks the ordinary rolling-upgrade sequence deployments will provide for you, and essentially nullifies any advantage you're getting from Kubernetes.</p>

<p>This almost looks like you're trying to use Kubernetes as a build environment.  Setting up a purpose-built or cloud-hosted tool for this will probably serve you better.  If you're trying to take your local source tree and <code>npm run build</code> on it, using a local Node installation will be much easier than what you've shown here.</p>
