I recently deployed my Next.js app via a dockerfile.
Below you can see the dockerfile.
FROM node:16-alpine AS builder
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY . .
# If using npm with a `package-lock.json` comment out above and use below instead
RUN npm ci
ENV NEXT_TELEMETRY_DISABLED 1
# If using npm comment out above and use below instead
RUN npx prisma migrate deploy
RUN npx prisma generate
RUN npm run build
# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app ./
USER nextjs
ENV PORT 3000
CMD ["npm", "run","start"]
Everything is running fine but I am getting these errors in my logs:
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] Failed to write image to cache WebTu42A6KiKAt3CuJRb11ifqOS7zrDpScVm6miEBwM= [Error: EACCES: permission denied, mkdir '/app/.next/cache/images'] {
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] errno: -13,
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] code: 'EACCES',
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] syscall: 'mkdir',
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] path: '/app/.next/cache/images'
2022-04-26T12:46:56.408 app[2bbc2a76] maa [info] }
I have a features in my which uses the local file storage(public folder) for temp uploads of txt files.( The feature is not implemented yet so I cant test it).
Any help to remove this permission denied error is appreciated.