将Node.js运行状况检查添加到多阶段Docker映像中

时间:2019-04-29 15:33:22

标签: node.js docker nginx

我有一个React应用程序在nginx容器中运行,如以下Dockerfile中所述。现在,我想在我的Dockerfile中添加一个HEALTHCHECK,看起来像这样:

HEALTHCHECK --interval=10s node /healthcheck.js

但是我不知道该怎么做。我是否需要在最终的Docker构建阶段中添加此运行状况检查?我猜nginx容器不能运行任何node命令?

还是我需要在“阶段1”中的某个地方添加健康检查?

Dockerfile

# Stage "0" - Create cached node_modules
# Only rebuilds layer if package.json has changed.
FROM node:10-alpine AS node_cache

WORKDIR /cache
COPY package.json package-lock.json ./
RUN npm install

# Stage 1 - Build the application using cached node layer
FROM node:10-alpine AS build-stage

WORKDIR /app
COPY --from=node_cache /cache/ .
COPY . ./

ARG REACT_APP_API_ENDPOINT
ENV REACT_APP_API_ENDPOINT $REACT_APP_API_ENDPOINT

RUN npm run build

# Stage 2 - Create the production image containing the compiled app only
FROM nginx:1.15-alpine

COPY --from=build-stage /app/build/ /usr/share/nginx/html

0 个答案:

没有答案