'Running Node with dumb-init inside a Docker Container

I am trying to use dumb-init in my docker container but the container OS cannot find the executable. My file is

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"]

and when I run it

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.


Solution 1:[1]

You final nodejs:16 image is a debian based image, you however need to install dumb-init on it.

RUN apt-get install dumb-init

on debian / ubuntu based images

RUN apk add dumb-init

on Alpine based images

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shan-Desai