forked from huanghanzhilian/c-shopping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
30 lines (28 loc) · 967 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
FROM node:18-alpine as dependencies
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm install
FROM node:18-alpine as builder
WORKDIR /app
COPY ./ ./
COPY ./.env ./
COPY --from=dependencies /app/node_modules ./node_modules
RUN npm run build
FROM node:18-alpine as runner
WORKDIR /app
ENV NODE_ENV production
COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/.env ./.env
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
ENV MONGODB_URL "mongodb://db:27017/choiceshop"
EXPOSE 3000
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN mkdir -p .next/cache/fetch-cache
RUN chown -R nextjs:nodejs .next
USER nextjs
# CMD echo 'Waiting for db service start...' && while ! nc -z db 27017; do sleep 1; done; echo 'Connected!' && npm run build && npm run start
CMD npm run start