File tree Expand file tree Collapse file tree 9 files changed +57
-4
lines changed
with-docker-compose/next-app Expand file tree Collapse file tree 9 files changed +57
-4
lines changed Original file line number Diff line number Diff line change 22
33FROM node:20-alpine
44
5+ # Install curl for health check
6+ RUN apk add --no-cache curl
7+
58WORKDIR /app
69
710# Install dependencies based on the preferred package manager
4144 else npm run build; \
4245 fi
4346
47+ # Health check for container orchestration (Docker, Kubernetes, etc.)
48+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
49+ CMD curl -f http://localhost:3000/api/health || exit 1
50+
4451# Start Next.js based on the preferred package manager
4552CMD \
4653 if [ -f yarn.lock ]; then yarn start; \
Original file line number Diff line number Diff line change 22
33FROM node:20-alpine AS base
44
5+ # Install curl for health check
6+ RUN apk add --no-cache curl
7+
58# Step 1. Rebuild the source code only when needed
69FROM base AS builder
710
@@ -72,4 +75,8 @@ ENV NEXT_PUBLIC_ENV_VARIABLE=${NEXT_PUBLIC_ENV_VARIABLE}
7275
7376# Note: Don't expose ports here, Compose will handle that for us
7477
78+ # Health check for container orchestration (Docker, Kubernetes, etc.)
79+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
80+ CMD curl -f http://localhost:3000/api/health || exit 1
81+
7582CMD ["node" , "server.js" ]
Original file line number Diff line number Diff line change 1+ // Health check endpoint for container orchestration (Docker, Kubernetes, etc.)
2+ // https://nextjs.org/docs/api-routes/introduction
3+
4+ export default function health ( req , res ) {
5+ res . status ( 200 ) . json ( { status : "ok" } ) ;
6+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ FROM node:20-alpine AS base
55# 1. Install dependencies only when needed
66FROM base AS deps
77# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8- RUN apk add --no-cache libc6-compat
8+ # curl is required for the health check in the runner stage.
9+ RUN apk add --no-cache libc6-compat curl
910
1011WORKDIR /app
1112
@@ -50,4 +51,8 @@ EXPOSE 3000
5051
5152ENV PORT=3000
5253
54+ # Health check for container orchestration (Docker, Kubernetes, etc.)
55+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
56+ CMD curl -f http://localhost:3000/api/health || exit 1
57+
5358CMD HOSTNAME="0.0.0.0" node server.js
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ FROM node:20-alpine AS base
55# 1. Install dependencies only when needed
66FROM base AS deps
77# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8- RUN apk add --no-cache libc6-compat
8+ # curl is required for the health check in the runner stage.
9+ RUN apk add --no-cache libc6-compat curl
910
1011WORKDIR /app
1112
@@ -51,4 +52,8 @@ EXPOSE 3000
5152
5253ENV PORT=3000
5354
55+ # Health check for container orchestration (Docker, Kubernetes, etc.)
56+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
57+ CMD curl -f http://localhost:3000/api/health || exit 1
58+
5459CMD HOSTNAME="0.0.0.0" node server.js
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ FROM node:20-alpine AS base
55# 1. Install dependencies only when needed
66FROM base AS deps
77# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8- RUN apk add --no-cache libc6-compat
8+ # curl is required for the health check in the runner stage.
9+ RUN apk add --no-cache libc6-compat curl
910
1011WORKDIR /app
1112
@@ -51,4 +52,8 @@ EXPOSE 3000
5152
5253ENV PORT=3000
5354
55+ # Health check for container orchestration (Docker, Kubernetes, etc.)
56+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
57+ CMD curl -f http://localhost:3000/api/health || exit 1
58+
5459CMD HOSTNAME="0.0.0.0" node server.js
Original file line number Diff line number Diff line change 1+ // Health check endpoint for container orchestration (Docker, Kubernetes, etc.)
2+ // https://nextjs.org/docs/api-routes/introduction
3+
4+ export default function health ( req , res ) {
5+ res . status ( 200 ) . json ( { status : "ok" } ) ;
6+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ FROM node:20-alpine AS base
55# Install dependencies only when needed
66FROM base AS deps
77# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8- RUN apk add --no-cache libc6-compat
8+ # curl is required for the health check in the runner stage.
9+ RUN apk add --no-cache libc6-compat curl
910WORKDIR /app
1011
1112# Install dependencies based on the preferred package manager
@@ -63,4 +64,9 @@ ENV PORT=3000
6364# server.js is created by next build from the standalone output
6465# https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
6566ENV HOSTNAME="0.0.0.0"
67+
68+ # Health check for container orchestration (Docker, Kubernetes, etc.)
69+ HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
70+ CMD curl -f http://localhost:3000/api/health || exit 1
71+
6672CMD ["node" , "server.js" ]
Original file line number Diff line number Diff line change 1+ // Health check endpoint for container orchestration (Docker, Kubernetes, etc.)
2+ // https://nextjs.org/docs/api-routes/introduction
3+
4+ export default function health ( req , res ) {
5+ res . status ( 200 ) . json ( { status : "ok" } ) ;
6+ }
You can’t perform that action at this time.
0 commit comments