slim
This commit is contained in:
1 parent
d0e72d0bfe
commit
82bbaa0e83
1 file changed
+35
-9
+35
-9
@@ -1,17 +1,43 @@
|
|||||||
# Use official Node.js LTS image
|
# ========== STAGE 1: Build ==========
|
||||||
FROM node:18
|
FROM node:18 AS builder
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy your files into the container
|
# Copy only what's needed to install dependencies first (for better cache)
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install dependencies without unnecessary cache
|
||||||
|
RUN npm ci --omit=dev
|
||||||
|
|
||||||
|
# Then copy the rest of the source
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Install dependencies (only Express in your case)
|
# Build the app (modify this command if you're not using a build script)
|
||||||
RUN npm install express
|
RUN npm run build
|
||||||
|
|
||||||
# Expose the port your server listens on
|
|
||||||
|
# ========== STAGE 2: Runtime ==========
|
||||||
|
FROM node:18-slim AS runtime
|
||||||
|
|
||||||
|
# Install runtime dependencies
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
tini \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built app from builder stage
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
COPY --from=builder /app/package*.json ./
|
||||||
|
|
||||||
|
# Set correct permissions if needed
|
||||||
|
RUN chown -R node:node /app
|
||||||
|
|
||||||
|
USER node
|
||||||
|
|
||||||
|
# Expose port (adjust if needed)
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the server
|
# Start the app
|
||||||
CMD ["node", "server.js"]
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
|
CMD ["node", "dist/server.js"]
|
||||||
Reference in new issue
Block a user