Add Docker improvements and containerization

This commit is contained in:
nate@necloud.us committed 2025-08-13 19:07:58 -04:00
1 parent 545cf4c8dc
commit fdda517e7b
8 files changed
+313 -14

No files matched your search

+27 -5
View File
@@ -1,25 +1,47 @@
# ===== STAGE 1: Dependency Installation =====
FROM node:18 AS deps
FROM node:20-slim AS deps
WORKDIR /app
# Copy package files and install dependencies
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
# ===== STAGE 2: Runtime =====
FROM node:18-slim
FROM node:20-slim
# Install tini for proper signal handling
RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for better security
RUN groupadd -r spelling && useradd -r -g spelling spelling
# Setup application directory
WORKDIR /app
COPY --from=deps /app /app
# Copy node modules and package files
COPY --from=deps /app/node_modules /app/node_modules
COPY --from=deps /app/package*.json /app/
# Copy application code
COPY . .
# Create and set permissions for data directory
RUN mkdir -p /app/data && chown -R spelling:spelling /app/data
# Switch to non-root user
USER spelling
# Set version label
LABEL version="1.1.0" \
description="Spelling Practice Application" \
maintainer="nmemmert"
# Expose application port
EXPOSE 3000
# Use tini as init process and start application
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["node", "server.js"]