在 Docker 容器内使用 dumb-init 运行 Node

Mik*_*e M 4 node.js docker tini

我试图在我的 docker 容器中使用 dumb-init,但容器操作系统找不到可执行文件。我的文件是

FROM node:16 AS builder

RUN apt update
RUN apt install dumb-init

WORKDIR /app

COPY package.json .

RUN yarn install

COPY . .

RUN yarn run build

FROM node:16 AS production

WORKDIR /app

COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/yarn.lock ./yarn.lock
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules

ENTRYPOINT ["/usr/bin/dumb-init", "--"]
CMD ["node", "dist/main"]
Run Code Online (Sandbox Code Playgroud)

当我运行它时

docker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/usr/bin/dumb-init": stat /usr/bin/dumb-init: no such file or directory: unknown.
Run Code Online (Sandbox Code Playgroud)

Sha*_*sai 6

您的最终nodejs:16映像是基于 Debian 的映像,但是您需要dumb-init在其上安装。

RUN apt-get install dumb-init
Run Code Online (Sandbox Code Playgroud)

基于 debian / ubuntu 的镜像

RUN apk add dumb-init
Run Code Online (Sandbox Code Playgroud)

基于阿尔卑斯山的图像