# Build from source using a multi-stage build FROM node:lts-bookworm AS builder WORKDIR /workspace # Install yarn globally as required by the project setup RUN npm install -g yarn # Install dependencies first to leverage caching COPY package.json . RUN yarn install # Copy the rest of the source and build the project COPY . . RUN yarn build # Final runtime image FROM node:lts-bookworm WORKDIR /workspace # Copy the built artifacts from the builder stage COPY --from=builder /workspace/dist /workspace/dist ENV NODE_ENV=production # Default command: expose the built library # Running dist/esm/index.js will import the library; this is a safe no-op script CMD ["node", "dist/esm/index.js"]
# Ignore node_modules and build outputs node_modules/ dist/ .env *.log .DS_Store npm-debug.log* yarn-error.log*
Summary of Docker build error - Failing step - [builder 3/7] RUN npm install -g yarn (Dockerfile: line 6) - Exit code - did not complete successfully: exit code: 1 - Exact error messages (preserved) - npm error code EEXIST - npm error path /usr/local/bin/yarn - npm error EEXIST: file already exists - npm error File exists: /usr/local/bin/yarn - npm error Remove the existing file and try again, or run npm - npm error with --force to overwrite files recklessly. - A complete log of this run can be found in: /root/.npm/_logs/2026-03-18T14_40_36_354Z-debug-0.log - Missing packages/files mentioned - Conflict due to an existing file: /usr/local/bin/yarn - Version mismatch / notices - npm notice New minor version of npm available! 11.9.0 -> 11.11.1 - npm notice To update run: npm install -g npm@11.11.1 - Additional context - The failure occurs during the npm install -g yarn step, which cannot overwrite the existing /usr/local/bin/yarn without force or removing the file.
# Build from source using a multi-stage build
FROM node:lts-bookworm AS builder
WORKDIR /workspace
# Install yarn globally as required by the project setup if not already present
RUN if command -v yarn >/dev/null 2>&1; then echo "yarn already installed"; else npm install -g yarn; fi
# Install dependencies first to leverage caching
COPY package.json .
RUN yarn install
# Copy the rest of the source and build the project
COPY . .
RUN yarn build
# Final runtime image
FROM node:lts-bookworm
WORKDIR /workspace
# Copy the built artifacts from the builder stage
COPY --from=builder /workspace/dist /workspace/dist
ENV NODE_ENV=production
# Default command: a lightweight no-op to verify the container starts
CMD ["node", "-e", "console.log('redlock library built and ready')"]