FROM node:slim WORKDIR /app # Cache npm installs by copying only package manifest first COPY package.json package-lock.json* ./ # Install dependencies (including devDependencies for a full build) RUN npm ci --silent # Copy the full repository COPY . . # Build from source RUN npm run build # Clean npm cache to reduce image size RUN npm cache clean --force || true # Default to an interactive shell so the container can be used as a workspace CMD ["bash"]
# Node modules will be installed in the image; ignore local modules and caches node_modules/ **/node_modules/ # Git and version control .git/ .gitignore # OS/Editor caches .DS_Store Thumbs.db # Logs npm-debug.log* npm-error.log* # Build outputs build/ esm/ dist/ # Tests and coverage test/ coverage/ # IDE folders .idea/ .vscode/ # Package manager files package-lock.json*
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
FROM node:slim AS builder WORKDIR /app # Copy manifest files and install dependencies COPY package.json package-lock.json* ./ RUN npm ci --silent # Copy the rest of the source and build COPY . . RUN npm run build # Runtime stage: only include built artifacts FROM node:slim AS runtime WORKDIR /app # Copy built artifacts from the builder COPY --from=builder /app/build /app/build COPY --from=builder /app/esm /app/esm COPY --from=builder /app/dayjs.min.js /app/dayjs.min.js CMD ["bash"]
# Node modules (may be huge, skip local copies) **/node_modules/ # Build outputs build/ esm/ dist/ # Tests and coverage test/ coverage/ # Git .git/ .gitignore # OS/Editor caches .DS_Store Thumbs.db # Logs npm-debug.log* npm-error.log* # IDE folders .idea/ .vscode/
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Build-stage: install dependencies and build from source
FROM node:slim AS builder
WORKDIR /app
# Install dependencies first to leverage caching; copy package manifests separately
COPY package.json .
COPY package-lock.json .
RUN if [ -f package-lock.json ]; then npm ci --silent; else npm install --silent; fi
# Copy the rest of the source code
COPY . .
# Build the project from source
RUN npm run build
# Final runtime image
FROM node:slim
WORKDIR /app
# Copy built artifacts and source from the builder
COPY --from=builder /app /app
# Default command: indicate the container is ready
CMD ["node","-e","console.log('dayjs container ready')"]
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Multi-stage build for Day.js library
FROM node:slim AS builder
WORKDIR /app
# Install dependencies first to leverage caching
COPY package.json .
COPY package-lock.json .
RUN if [ -f package-lock.json ]; then npm ci --silent; else npm install --silent; fi
# Copy the rest of the source code
COPY . .
# Build the project from source
RUN npm run build
# Final runtime image
FROM node:slim
WORKDIR /app
# Copy built artifacts from builder (avoid shipping dev dependencies)
COPY --from=builder /app/build ./build
COPY --from=builder /app/esm ./esm
COPY --from=builder /app/dayjs.min.js ./dayjs.min.js
# Provide package.json for consumers requiring the package metadata
COPY package.json ./package.json
# Default command for a lightweight container; this can be overridden
CMD ["node","-e","console.log('dayjs container ready')"]
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Multi-stage build: build from source, then ship built artifacts only
FROM node:slim AS builder
WORKDIR /app
# Install dependencies first to leverage caching; use package-lock.json when available
COPY package.json .
COPY package-lock.json .
RUN if [ -f package-lock.json ]; then npm ci --silent; else npm install --silent; fi
# Copy the rest of the source code
COPY . .
# Build the project from source
RUN npm run build
# Final runtime image
FROM node:slim
ENV NODE_ENV=production
# Timezone handling: allow overriding at runtime, but defaults to UTC
ENV TZ=UTC
WORKDIR /app
# Copy only the artifacts we need from the builder to keep image small
COPY --from=builder /app/dayjs.min.js ./dayjs.min.js
COPY --from=builder /app/esm ./esm
COPY --from=builder /app/build ./build
COPY --from=builder /app/package.json ./package.json
# Default command prints a ready message; override as needed in your deployment
CMD ["node","-e","console.log('dayjs container ready')"]
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Syntax: dockerfile FROM node:slim AS builder WORKDIR /app # Install dependencies COPY package.json package-lock.json ./ RUN npm install # Copy source and build COPY . . RUN npm run build # Final runtime image FROM node:slim WORKDIR /usr/src/app # Copy built artifacts from builder COPY --from=builder /app /usr/share/dayjs # Keep the container running; this image is intended to provide built artifacts # You can run a quick shell or a lightweight test against the artifacts if needed CMD ["tail", "-f", "/dev/null"]
# Syntax: dockerfile
FROM node:slim AS builder
WORKDIR /app
# Install dependencies
COPY package.json package-lock.json ./
RUN npm install
# Copy source and build
COPY . .
RUN npm run build
# Final runtime image
FROM node:slim
WORKDIR /usr/src/app
# Copy built artifacts from builder (only essential files)
COPY --from=builder /app/dayjs.min.js /usr/src/app/dayjs.min.js
COPY --from=builder /app/esm /usr/src/app/esm
# Optional: copy build output if present
COPY --from=builder /app/build /usr/src/app/build
# Expose a minimal runtime entrypoint. This container hosts built artifacts; provide a simple startup message.
CMD ["node", "-e", "console.log('Day.js runtime container ready. Built artifacts available in /usr/src/app.')"]
# Syntax: dockerfile
FROM node:slim AS builder
WORKDIR /app
# Install build tools (needed for native modules during npm install)
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 g++ make \
&& rm -rf /var/lib/apt/lists/*
# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci
# Copy source and build
COPY . .
RUN npm run build
# Final runtime image
FROM node:slim
WORKDIR /usr/src/app
# Copy built artifacts from builder
COPY --from=builder /app /usr/src/app
# Default command: simply print a status message (library container)
CMD ["node", "-e", "console.log('Day.js runtime container ready. Built artifacts available in /usr/src/app.')"]
# Ignore files not needed in the build context .git node_modules build dist esm coverage test-results.xml *.log *.ts *.map docs patches
ERROR: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
# Syntax: dockerfile
FROM node:18-slim AS builder
WORKDIR /app
# Install build tools (needed for native modules during npm install)
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 g++ make \
&& rm -rf /var/lib/apt/lists/*
# Install dependencies
COPY package.json package-lock.json ./
RUN npm ci --silent
# Copy source and build
COPY . .
RUN npm run build
# Final runtime image
FROM node:18-slim
WORKDIR /usr/src/app
# Copy built artifacts from builder
COPY --from=builder /app/dayjs.min.js ./dayjs.min.js
COPY --from=builder /app/esm ./esm
COPY --from=builder /app/build ./build
# Default command: simply print a status message (library container)
CMD ["node", "-e", "console.log('Day.js runtime container ready. Built artifacts available in /usr/src/app.')"]