Next.js Discord

Discord Forum

Docker RUN npm run build Permission Denied

Unanswered
Cordilleran Flycatcher posted this in #help-forum
Open in Discord
Cordilleran FlycatcherOP
I'm trying deploy into a docker container. I have my dockerfile set up,
however when I reach RUN npm run build, I receive a permission denied error.
I'm not sure what to adjust, and would love any advice! Thank you!

# We use a the most current alpine OS for this, rather than any designated. 
FROM node:current-alpine3.17 AS Build
# Install dependencies only when needed
# 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 package.json package-lock.json ./

RUN npm ci

COPY . .


RUN npm run build # ERROR HERE ##################################################################################################################################


#########

# Multistage

FROM node:current-alpine3.17

# update, upgrade, https://github.com/Yelp/dumb-init, name the user nextuser
RUN apk update && apk upgrade && apk add dumb-init && adduser -D nextuser


#Set working Directory
WORKDIR /app

# If you use the public folder, this includes it in the project
# COPY --from=build --chown=nextuser:nextuser /app/public ./public 

# Copy out from the standalone build
COPY --from=Build --chown=nextuser:nextuser /app/.next/standalone ./
# Copy out static from .next folder
COPY --from=Build --chown=nextuser:nextuser /app/.next/static ./.next/static

# Detach from root
USER nextuser

# Set our port
EXPOSE 3000

# Set host port and node env
ENV HOST=0.0.0.0 PORT=3000 NODE_ENV=production

CMD ["dumb-init","node","server.js"]

2 Replies

Cordilleran FlycatcherOP
> global-events@0.1.0 build
                           > next build

sh: next: Permission denied
Error:building at STEP "RUN npm run build": while running runtime: exit status 126
Error message inquestion