<p>Because you are setting the container's <code>WORKDIR</code> to <code>/app/build</code> so your package.json is not in the working directory, but in the parent of the working directory.</p>

CC BY-SA 4.0
2018-11-14T19:53:53.013Z
But i never build the file using Dockerfile.I am just building the image using docker commands which will copy the entire pwd into app folder in docker container.
Rajat Seeddharth
CC BY-SA 4.0
2018-11-14T19:57:40.353Z
How would you call the process when your docker copies the app folder into the container? What command do you use to achieve it? And what is more important where is your package.json located?
lependu
CC BY-SA 4.0
2018-11-15T04:56:06.083Z
`docker run --rm -v `pwd`:/app -w /app node yarn build` in this command -v is used fr mounting the volume which says to mount the cwd folder into the /app folder in container process so it kind in a way copies it in /app in container. -w is to change the folder to app in container and execute the command.
Rajat Seeddharth
CC BY-SA 4.0
2018-11-15T08:59:30.563Z
So you have never ran `docker build -t [your-image-name] .`? Can you please check the working directory in the container (pwd) and the directory content (ls).
lependu
CC BY-SA 4.0
2018-11-14T08:25:28.367Z
2018-11-14T08:25:28.367Z
lependu
<p>My Dockerfile looks something like this.</p>

<pre><code>FROM mhart/alpine-node:8.11.3

RUN mkdir -p /app
COPY ./ /app

WORKDIR /app/build

RUN yarn global add serve
CMD ["serve", "-l", "3000"]

EXPOSE 3000
</code></pre>

<p>And then JenkinsFile looks something like this.</p>

<pre><code> node {
  try {

    stage('Checkout source code') {
        checkout scm
    }

    stage('Install packages') {
      sh("docker run --rm -v `pwd`:/app -w /app node yarn install")
      //sh("sudo chown -R jenkins: ./node_modules")
    }

    stage('Set the enviroment variables') {
      sh("echo set-env-variables")
      }

    stage('Build static assets') {

      sh("docker run --rm -v `pwd`:/app -w /app node yarn build")
    }
  }}
</code></pre>

<p>When I do run it on Jenkins,the console output says error Couldn't find a <code>package.json</code> file in "/app" and also it gives an <code>error sudo not found</code> even though I have added Jenkins <code>ALL=(ALL) NOPASSWD: ALL</code> to <code>/etc/sudoers</code> file.</p>

<p>I run the commands listed in my Jenkinsfile on my terminal and they all work fine but when i run them on Jenkins , they dont work.</p>

<docker><jenkins><jenkins-pipeline><dockerfile><jenkinsfile>
packge.json not found while executing on Jenkins
Rajat Seeddharth
# packge.json not found while executing on Jenkins

(Asked by: username_0 on 2018-11-13)

My Dockerfile looks something like this.
FROM mhart/alpine-node:8.11.3

RUN mkdir -p /app
COPY ./ /app

WORKDIR /app/build

RUN yarn global add serve
CMD ["serve", "-l", "3000"]

EXPOSE 3000

And then JenkinsFile looks something like this.
 node {
  try {

    stage('Checkout source code') {
        checkout scm
    }

    stage('Install packages') {
      sh("docker run --rm -v `pwd`:/app -w /app node yarn install")
      //sh("sudo chown -R jenkins: ./node_modules")
    }

    stage('Set the enviroment variables') {
      sh("echo set-env-variables")
      }

    stage('Build static assets') {

      sh("docker run --rm -v `pwd`:/app -w /app node yarn build")
    }
  }}

When I do run it on Jenkins,the console output says error Couldn't find a package.json file in "/app" and also it gives an error sudo not found even though I have added Jenkins ALL=(ALL) NOPASSWD: ALL to /etc/sudoers file.
I run the commands listed in my Jenkinsfile on my terminal and they all work fine but when i run them on Jenkins , they dont work.

**Tags:** docker, jenkins, jenkins-pipeline, dockerfile, jenkinsfile


---

## 1 answers

### Answer by username_1 on 2018-11-14. Score: 1

Because you are setting the container's `WORKDIR` to `/app/build` so your package.json is not in the working directory, but in the parent of the working directory.

> **Comments:**
> **username_0**: But i never build the file using Dockerfile.I am just building the image using docker commands which will copy the entire pwd into app folder in docker container.  
> **username_1**: How would you call the process when your docker copies the app folder into the container? What command do you use to achieve it? And what is more important where is your package.json located?  
> **username_0**: `docker run --rm -v `pwd`:/app -w /app node yarn build` in this command -v is used fr mounting the volume which says to mount the cwd folder into the /app folder in container process so it kind in a way copies it in /app in container. -w is to change the folder to app in container and execute the command.  
> **username_1**: So you have never ran `docker build -t [your-image-name] .`? Can you please check the working directory in the container (pwd) and the directory content (ls).  

---

