Skip to content

Commit

Permalink
fixed double installation in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsingal committed Apr 27, 2022
1 parent cbf840d commit 51727e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
.yarn/cache
18 changes: 5 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
FROM node:16.14-alpine3.15 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 git
RUN corepack enable
WORKDIR /app
COPY package.json yarn.lock ./

RUN corepack enable
COPY .yarn ./.yarn
COPY package.json yarn.lock .yarnrc.yml ./
RUN yarn install --immutable

# If using npm with a `package-lock.json` comment out above and use below instead
Expand All @@ -17,20 +15,13 @@ RUN yarn install --immutable
FROM node:16.14-alpine3.15 AS builder
WORKDIR /app
COPY . .
COPY --from=deps /app/.yarn ./.yarn
COPY --from=deps /app/.pnp.cjs /app/.pnp.loader.mjs ./
RUN corepack enable
COPY --from=deps /app/node_modules ./node_modules

# 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 during the build.
ENV NEXT_TELEMETRY_DISABLED 1

# Prior to yarn 3, this 2nd call to "yarn install" would not be needed
# However, stuff breaks without it. We do carry over the cache from the previous step,
# so it is faster than a cold install
# TODO: figure out how to not have to run "yarn install" a 2nd time
RUN yarn install --immutable
RUN yarn build

# Production image, copy all the files and run next
Expand All @@ -51,7 +42,8 @@ COPY --from=builder /app/package.json ./package.json

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.9" # optional since v1.27.0
services:
app:
build: .
ports:
- "3000:3000"

0 comments on commit 51727e0

Please sign in to comment.