3

I have a basic NextJS setup with a custom Express server.

I'm trying to Dockerize the app. Here is my Dockerfile:

FROM node:alpine

WORKDIR /usr/app

RUN npm install --global pm2

COPY ./package.json ./

RUN yarn docker:build

COPY ./ ./

RUN yarn build

EXPOSE 3000

USER node

CMD [ "pm2-runtime", "yarn", "dev" ]

My docker:build command is,

rm -rf node_modules && rm -rf yarn.lock yarn && yarn

Anyway, I try to run docker-compose up and I run into the below error:

nextjs_1  | /opt/yarn-v1.22.5/bin/yarn:2
nextjs_1  | argv0=$(echo "$0" | sed -e 's,\\,/,g')
nextjs_1  |         ^^^^
nextjs_1  | SyntaxError: missing ) after argument list
nextjs_1  |     at wrapSafe (node:internal/modules/cjs/loader:1018:16)
nextjs_1  |     at Module._compile (node:internal/modules/cjs/loader:1066:27)
nextjs_1  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1131:10)

I have no idea what I'm doing wrong here.

I've simplified my setup in a repo here.

Any help would be appreciated.

Github issue

1
  • Why not just RUN yarn at that step (the image won't have a node_modules directory yet, and you don't want to delete the lock file)? Does that error come when building the image or running it? Are you doing something that might cause the yarn script wrapper to be interpreted with Node? Commented Nov 21, 2020 at 0:41

1 Answer 1

1
diff --git a/Dockerfile b/Dockerfile
index 658452d..8e2fe06 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -28,4 +28,4 @@ EXPOSE 3000
 USER node
 
 # Run npm start script when container starts
-CMD [ "pm2-runtime", "yarn", "dev" ]
\ No newline at end of file
+CMD [ "pm2-runtime", "start", ".next/production-server/server.js" ]
/usr/app # pm2-runtime start .next/production-server/server.js 
2020-11-21T05:51:18: PM2 log: Launching in no daemon mode
2020-11-21T05:51:18: PM2 log: App [server:0] starting in -fork mode-
2020-11-21T05:51:18: PM2 log: App [server:0] online
event - compiled successfully
App listening on port 3000

When next builds, it drops the compiled JavaScript into .next folder. Additionally, pm2 takes a start command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.