-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce docker image size
- Loading branch information
Showing
3 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"socialify": patch | ||
--- | ||
|
||
Improve docker build process | ||
Reduce docker image size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,5 @@ yarn-error.log* | |
|
||
.dockerignore | ||
Dockerfile | ||
.* | ||
.* | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
# Source: https://github.com/vercel/next.js/blob/2161d8c012dcd98eb8690814bd275d56c45bf00a/examples/with-docker/Dockerfile | ||
|
||
FROM node:22-alpine AS base | ||
|
||
# Stage 1: Install dependencies | ||
FROM base AS deps | ||
WORKDIR /app | ||
COPY package.json yarn.lock ./ | ||
# postinstall script requires a public directory | ||
RUN mkdir -p /app/public && \ | ||
yarn install --frozen-lockfile | ||
|
||
# Stage 2: Build the application | ||
FROM base AS builder | ||
|
||
ENV NODE_ENV=production | ||
ENV CI=true | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=deps /app/node_modules ./node_modules | ||
COPY . . | ||
COPY --from=deps /app/public ./public | ||
|
||
RUN yarn build | ||
|
||
# Stage 3: Prepare the production image | ||
FROM base AS runner | ||
|
||
ENV GITHUB_TOKEN= | ||
ENV PROJECT_URL=http://localhost:3000 | ||
ENV GTM_ID= | ||
|
||
ENV PORT=3000 | ||
ENV NODE_ENV=production | ||
ENV CI=true | ||
ENV NEXT_TELEMETRY_DISABLED=1 | ||
|
||
WORKDIR /app | ||
|
||
COPY package.json yarn.lock* ./ | ||
COPY public ./public/ | ||
RUN yarn --frozen-lockfile | ||
# Copy only the necessary files and install production dependencies | ||
COPY package.json yarn.lock ./ | ||
RUN mkdir -p /app/public && \ | ||
yarn install --production --frozen-lockfile && \ | ||
yarn cache clean | ||
|
||
COPY . . | ||
|
||
RUN yarn build | ||
|
||
CMD ["yarn", "start"] | ||
COPY --from=builder /app/.next ./.next | ||
COPY --from=builder /app/public ./public | ||
COPY --from=builder /app/next.config.js /app/custom-rewrites.js ./ | ||
|
||
EXPOSE 3000 | ||
|
||
CMD ["yarn", "start"] |