next.config.js
/** @type {import('next').NextConfig} */ import { writeFileSync } from 'fs'; const nextConfig = { reactStrictMode: false, output: 'standalone',
}; export default nextConfig;
standalone --> CMD ["node", "server.js"] --> sẻ chạy port 3000
Dockerfile
FROM node:latest AS base FROM base AS builder
WORKDIR /app
RUN corepack enable
COPY package*.json yarn.lock* ./
RUN yarn COPY . .
RUN yarn build FROM base AS production
WORKDIR /app
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
CMD ["node", "server.js"]
docker-compose.yml
version: "3.8" services: nextjs: ports: - 3024:3000 container_name: emr_web image: emr_web:latest restart: always build: context: ./ dockerfile: Dockerfile environment: NEXT_PUBLIC_URL_BE: https://xx NEXT_PUBLIC_LOGO: ''
.dockerignore
node_modules
.next
.github
.husky
.yarn
Run docker
- docker-compose down --volumes --remove-orphans - docker-compose up -d --force-recreate --build
docker images REPOSITORY TAG IMAGE ID CREATED SIZE
abi latest cd9a4334fde0 10 hours ago 1.15GB
Dung lượng đã giảm rất nhiều
Gitlab CI/CD runer
stages: - build cache: key: ${CI_COMMIT_REF_SLUG} paths: - node_modules/ - .next variables: DOCKER_BUILDKIT: 1 before_script: - git submodule sync --recursive - git submodule update --init --recursive build_dev: stage: build script: - export DOCKER_BUILDKIT=1 - docker-compose down --volumes --remove-orphans - docker-compose up -d --force-recreate --build tags: - abi only: - main