- vừa được xem lúc

Build Nextjs 14 Docker Compose

0 0 4

Người đăng: huyi

Theo Viblo Asia

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

Bình luận

Bài viết tương tự

- vừa được xem lúc

Docker: Chưa biết gì đến biết dùng (Phần 1- Lịch sử)

1. Vì sao nên sử dụng. . .

0 0 99

- vừa được xem lúc

Docker: Chưa biết gì đến biết dùng (Phần 2 - Dockerfile)

1. Mở đầu.

0 0 62

- vừa được xem lúc

Docker: Chưa biết gì đến biết dùng (Phần 3: Docker-compose)

1. Mở đầu. . .

0 0 116

- vừa được xem lúc

Set up private docker registry

Bài toán: Mình cần 1 repository để lưu trữ Docker Images của mỗi lần build. -> Docker hub chỉ cho duy nhất 1 private repos, còn lại sẽ mất phí hoặc phải để public. tham khảo ở đây ([Docker Hub])(https://www.docker.

0 0 61

- vừa được xem lúc

Spring boot Kotlin Auto Build on Docker Compose Runtime

Trong khi phát triển một ứng dụng Spring boot sử dụng ngôn ngữ Kotlin với docker phải thông qua quá trình build mới có thể start được server cho nên khi phát triển sẽ sửa code liên tục cần nó tự động nhận code mới. Vậy trong bài viết này sẽ giới thiệu qua về giải pháp tận dụng một công cụ entr để lắ

0 0 28

- vừa được xem lúc

Tìm hiểu về Docker Compose CLI

Ở bài trước, chúng ta đã cùng nhau tìm hiểu về Docker Compose và cách config 1 docker compose file. . . Docker Compose là một công cụ giúp định nghĩa và run mutil-docker-container.

0 0 33