Skip to content

Instantly share code, notes, and snippets.

@happygrizzly
Last active June 22, 2021 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happygrizzly/00f073d1cbdf942b0f93aaa839a241ae to your computer and use it in GitHub Desktop.
Save happygrizzly/00f073d1cbdf942b0f93aaa839a241ae to your computer and use it in GitHub Desktop.
strapi-corporate-starter-dockerfiles
version: '3'
services:
strapi:
build: ./backend
image: dockerhubid/project-cms:latest
ports:
- '1337:1337'
next:
build: ./frontend
image: dockerhubid/project-webui:latest
ports:
- '3000:3000'
# ref: https://nextjs.org/docs/deployment
# ref: https://steveholgado.com/nginx-for-nextjs/#dockerising-nextjs
# Install dependencies only when needed
FROM node:alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Rebuild the source code only when needed
FROM node:alpine AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/node_modules ./node_modules
RUN yarn build && yarn install --production --ignore-scripts --prefer-offline
# Production image, copy all the files and run next
FROM node:alpine AS runner
WORKDIR /app
RUN npm install --global pm2
ENV NODE_ENV production
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
USER nextjs
EXPOSE 3000
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
# Run npm start script with PM2 when container starts
CMD [ "pm2-runtime", "npm", "--", "start" ]
# ref: https://github.com/strapi/strapi-docker/blob/master/examples/custom/Dockerfile
FROM strapi/base
WORKDIR /app
COPY ./package.json ./
COPY ./yarn.lock ./
RUN yarn install
COPY . .
RUN npm install --global pm2
ENV NODE_ENV production
ENV STRAPI_LOG_LEVEL error
RUN yarn build
EXPOSE 1337
# Run npm start script with PM2 when container starts
CMD [ "pm2-runtime", "npm", "--", "start" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment