Next.js 로 작성한 사이트를 Docker로 빌드해서 컨테이너를 ECS로 서비스 한다.
next.js / examples / with-docker
output
옵션으로 standalone
주기module.exports = {
output: 'standalone',
}
FROM node:16-alpine AS base
### BUILD ###
FROM base AS builder
WORKDIR /usr/src/app
COPY . .
RUN yarn --frozen-lockfile
RUN yarn build
### RUN ###
FROM base As runner
WORKDIR /usr/src/app
ENV HOSTNAME localhost
ENV PORT 3000
ENV NODE_ENV production
COPY --from=builder $APP_PATH/public ./public
COPY --from=builder $APP_PATH/.next/standalone ./
COPY --from=builder $APP_PATH/.next/static ./.next/static
EXPOSE 3000
CMD ["node", "server.js"]
$ docker build -t nextjs-site .
$ docker run -p 80:3000 nextjs-site
FROM node:16-alpine AS base
### BUILD ###
FROM base AS builder
WORKDIR /usr/src/app
COPY . .
RUN yarn --frozen-lockfile
RUN yarn build
### RUN ###
FROM base As runner
WORKDIR /usr/src/app
ENV HOSTNAME localhost
ENV PORT 3000
ENV NODE_ENV production
COPY --from=builder $APP_PATH/public ./public
COPY --from=builder $APP_PATH/.next/standalone ./
COPY --from=builder $APP_PATH/.next/static ./.next/static
EXPOSE 3000
CMD ["node", "server.js"]
감사합니다. 이런 정보를 나눠주셔서 좋아요.