I'm trying to Dockerize a basic NextJS setup with nginx based on this tutorial.
I have a NextJS app written in typescript and with a custom Express server, which I deploy to Heroku. It builds and the server file at .next/production-server/server.js gets served.
When I try to Dockerize the app as in the above guide, I run in the error,
Getting error Error: EACCES: permission denied, unlink '/usr/app/.next/BUILD_ID'
I've tried running chmod to grant access to the node user from node alpine, but it keeps throwing the same error.
I'm not sure what I'm doing wrong. If I were to clone the repo from here, directly from that guide, and run docker-compose up, then it seems to work fine. But it seems that the moment I try to add TS configuration to it, it fails.
FROM node:alpine
WORKDIR /usr/app
RUN npm install --global pm2
COPY ./package.json ./
RUN npm install --production
COPY ./ ./
RUN npm run build
USER node # <----------------- seems to fail with this user
EXPOSE 3000
CMD [ "pm2-runtime", "start", "npm", "--", "start" ]
My Github repo is here.
If comment out the line USER node, then it works fine.