#Error step npm run build

4 messages · Page 1 of 1 (latest)

thorn geyser
#

I get an error when build docker image with this setup

FROM node:16-alpine as builder
WORKDIR /usr/src/app
COPY ["package*.json", "tsconfig.*", "nest-cli.json", "src", "libs",  "config", "./"]
# COPY . .
RUN npm install
RUN npm run build

FROM node:16-alpine
WORKDIR /app
COPY --from=builder /usr/src/app/package.json /usr/src/app/dist ./
COPY --from=builder /usr/src/app/node_modules ./node_modules

# Create a group and user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
RUN chown -R appuser:appgroup /usr/src/app

# Tell docker that all future commands should run as the appuser user
USER appuser

CMD ["node", "dist/main"]

I attach my folder structure and error facing.

if I replace COPY ["package*.json", "tsconfig.*", "nest-cli.json", "src", "libs", "config", "./"] to # COPY . . It work ok
Can't found where I missing. Please help me thank you

steady helm
#

Unfortunately COPY doesn't allow copying multiple directories like this.
You'll have to split the copy instructions:

COPY ["package*.json", "tsconfig.*", "nest-cli.json", "./"]
COPY ["src", "src"]
COPY ["libs", "libs"]
COPY ["config", "config"]

Also, it'll be more efficient to copy the package.json, run npm install, and then copy the source code.
Docker caches the steps, and only re-runs the instruction if the file changes - while package.json rarely changes, src contents change always. So this should work better:

COPY ["package*.json", "tsconfig.*", "nest-cli.json", "./"]
RUN npm install
COPY ["src", "src"]
COPY ["libs", "libs"]
COPY ["config", "config"]
RUN npm run build
thorn geyser
#

thank you @steady helm but if use like this then need 3 more layer. Is it still good?

COPY ["src", "src"]
COPY ["libs", "libs"]
COPY ["config", "config"]```
#

aw nvm I got your idea thank you again