NextJS unable to build in docker
Unanswered
Georgian Shepherd posted this in #help-forum
Georgian ShepherdOP
Hi all,
I have a nextjs app that works fine when run from the command line, but as soon as I add a dockerfile, it fails to find the /app or /pages folder
The structure is
/<MyApp>
/src
/app
And my docker file is as follows
but I get this error
when it tries to execute npm install.
any suggestions?
I have a nextjs app that works fine when run from the command line, but as soon as I add a dockerfile, it fails to find the /app or /pages folder
The structure is
/<MyApp>
/src
/app
And my docker file is as follows
FROM node:20
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies for the project
RUN npm install
# Copy the entire project
COPY . .
# Set the environment variable
ENV NODE_ENV=production
# Build the Next.js application
RUN npm run build
# Expose the application port
EXPOSE 3000
# Start the application
CMD ["npm", "start"]but I get this error
16.13 > Build error occurred
16.13 Error: > Couldn't find any `pages` or `app` directory. Please create one under the project root
16.13 at findPagesDir (/app/node_modules/next/dist/lib/find-pages-dir.js:42:15)
16.13 at <unknown> (/app/node_modules/next/dist/build/index.js:418:73)
16.13 at async Span.traceAsyncFn (/app/node_modules/next/dist/trace/trace.js:153:20)
16.13 at async build (/app/node_modules/next/dist/build/index.js:361:9)when it tries to execute npm install.
any suggestions?
3 Replies
Giant Angora
Your in the wrong working dir. You should be at root
@Giant Angora Your in the wrong working dir. You should be at root
Georgian ShepherdOP
that makes sense - will try later today
Georgian ShepherdOP
Sorry forgot to reply, but the problem ended up being the copy, it wasn't copying anything so I had to copy all the stuff I wanted individually