Created
January 17, 2024 19:11
-
-
Save dietrichmax/f14547acd4eb9c21280cf87c09783844 to your computer and use it in GitHub Desktop.
Dockerize existing Strapi v3
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
FROM node:14 AS base | |
# Install dependencies only when needed | |
FROM base AS deps | |
WORKDIR /app | |
# Install dependencies based on the preferred package manager | |
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ | |
RUN npm install | |
# Rebuild the source code only when needed | |
FROM base AS builder | |
WORKDIR /app | |
COPY --from=deps /app/node_modules ./node_modules | |
COPY . . | |
RUN NODE_ENV=production npm run build | |
# Production image, copy all the files and run next | |
FROM base AS runner | |
WORKDIR /app | |
ENV NODE_ENV production | |
RUN addgroup --system --gid 1001 nodejs | |
RUN adduser --system --uid 1001 strapi | |
# Set the correct permission for prerender cache | |
RUN mkdir build | |
RUN chown strapi:nodejs build | |
# Automatically leverage output traces to reduce image size | |
# https://nextjs.org/docs/advanced-features/output-file-tracing | |
COPY --from=builder --chown=strapi:nodejs /app ./ | |
USER strapi | |
EXPOSE 1337 | |
ENV PORT 1337 | |
# set hostname to localhost | |
ENV HOSTNAME "0.0.0.0" | |
# server.js is created by next build from the standalone output | |
# https://nextjs.org/docs/pages/api-reference/next-config-js/output | |
CMD ["npm", "run", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment