Dockerupdate

This commit is contained in:
mukesh13
2025-06-23 21:45:08 +05:30
parent a62ec1fc70
commit acf1c4ef7d

View File

@ -1,68 +1,59 @@
# syntax=docker/dockerfile:1.4 # syntax=docker/dockerfile:1.4
# 1. For build React app # Use Alpine for smaller size and faster package manager
FROM node:lts AS development FROM node:lts-alpine AS development
# Set working directory
WORKDIR /app WORKDIR /app
# Install system dependencies needed for sharp # Install dependencies using apk (much faster than apt)
RUN apt-get update && apt-get install -y \ RUN --mount=type=cache,target=/var/cache/apk \
libvips-dev \ apk add --update --no-cache \
vips-dev \
python3 \ python3 \
make \ make \
g++ \ g++
&& rm -rf /var/lib/apt/lists/*
# Copy package files # Copy package files
COPY package.json /app/package.json COPY package.json package-lock.json ./
COPY package-lock.json /app/package-lock.json
# Install dependencies normally first # Install npm dependencies with cache
RUN npm ci --legacy-peer-deps --ignore-scripts RUN --mount=type=cache,target=/root/.npm \
npm ci --legacy-peer-deps --ignore-scripts
# Then install sharp properly for the current platform # Install sharp
RUN npm install --platform=linux --arch=x64 sharp RUN --mount=type=cache,target=/root/.npm \
npm install --platform=linux --arch=x64 sharp
COPY . /app COPY . .
ENV CI=true ENV CI=true
ENV PORT=3000 ENV PORT=3000
CMD [ "npm", "start" ] CMD [ "npm", "start" ]
# Build stage
FROM development AS build FROM development AS build
RUN npm run build RUN npm run build
# Development with tools
FROM development as dev-envs FROM development as dev-envs
RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF
RUN <<EOF RUN --mount=type=cache,target=/var/cache/apk \
useradd -s /bin/bash -m vscode apk add --no-cache git
groupadd docker
usermod -aG docker vscode RUN adduser -D -s /bin/sh vscode && \
EOF addgroup docker && \
# install Docker tools (cli, buildx, compose) addgroup vscode docker
COPY --from=gloursdocker/docker / / COPY --from=gloursdocker/docker / /
CMD [ "npm", "start" ] CMD [ "npm", "start" ]
# 2. For Nginx setup # Production
FROM nginx:alpine FROM nginx:alpine AS production
# Copy config nginx
COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build /app/.nginx/nginx.conf /etc/nginx/conf.d/default.conf
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
# Remove default nginx static assets
RUN rm -rf ./* RUN rm -rf ./*
# Copy static assets from builder stage
COPY --from=build /app/build . COPY --from=build /app/build .
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"] ENTRYPOINT ["nginx", "-g", "daemon off;"]