From 1148382faff21378144243bdd225bb3301d3cbf9 Mon Sep 17 00:00:00 2001 From: Shaun Millar Date: Sat, 23 Mar 2024 16:16:58 -0700 Subject: [PATCH] simplfied dockerfile added ignore file --- web_app/.dockerignore | 4 +++ web_app/Dockerfile | 57 ++++++++++++------------------------------- 2 files changed, 20 insertions(+), 41 deletions(-) create mode 100644 web_app/.dockerignore diff --git a/web_app/.dockerignore b/web_app/.dockerignore new file mode 100644 index 00000000..54f1b9f5 --- /dev/null +++ b/web_app/.dockerignore @@ -0,0 +1,4 @@ +**/bin +**/obj +**/node_modules +.git \ No newline at end of file diff --git a/web_app/Dockerfile b/web_app/Dockerfile index 212ea9da..c5897e95 100644 --- a/web_app/Dockerfile +++ b/web_app/Dockerfile @@ -1,50 +1,25 @@ -FROM node:18-alpine AS base -RUN apk add --no-cache g++ make py3-pip libc6-compat -WORKDIR /app -COPY package*.json ./ -EXPOSE 3000 +# Dockerfile for NextJS applications -FROM base AS builder -WORKDIR /app -COPY . . -RUN npm run build +# Use the official Node.js image as base +FROM node:18-alpine -FROM base AS production +# Set the working directory inside the container WORKDIR /app -# ENV NODE_ENV production -RUN npm ci --ignore-scripts - -RUN addgroup -g 1003 -S nodegroup -RUN adduser -S nextuser -u 1003 -USER nextuser - -COPY --from=builder /app/.next ./.next -RUN chown nextuser:nodegroup ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/public ./public - -CMD npm start - -FROM base AS dev -RUN npm install +# Copy package.json and package-lock.json to the container +COPY package*.json ./ -COPY package.json . -COPY package-lock.json . -COPY /node_modules ./node_modules -COPY /src ./src -COPY /public ./public -COPY next.config.mjs . -COPY next-env.d.ts . -COPY tsconfig.json . -COPY .eslintrc.json . +# Install dependencies +RUN npm install -RUN addgroup -g 1003 -S nodegroup -RUN adduser -S nextuser -u 1003 +# Copy the rest of the application code to the container +COPY . . -RUN chown -R nextuser:nodegroup /app +# Build the Next.js application +RUN npm run build -USER nextuser +# Expose the port that your Next.js app runs on +EXPOSE 3000 -CMD npm run dev \ No newline at end of file +# Command to run the application +CMD ["npm", "start"] \ No newline at end of file