Docker error after CTRL+C: Cannot kill container

  docker, docker-compose, javascript, next.js, node.js

Please help me with the correct Dockerfile for the NextJS application.
I’m trying to use these example from official repository: https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile.multistage

My Dockerfile:

# Stage 1: Building the code
FROM node:[email protected]:5edad160011cc8cfb69d990e9ae1cb2681c0f280178241d58eba05b5bfc34047 AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
ENV NODE_ENV production
RUN npm run build
RUN npm ci --only=production
# Stage 2: And then copy over node_modules, etc from that stage to the smaller base image
FROM node:[email protected]:f07d995a6b0bb73e3bd8fa42ba328dd0481f4f0a4c0c39008c05d91602bba6f1 as production
USER node
ARG PORT
WORKDIR /app
# COPY package.json next.config.js .env* ./
COPY --chown=node:node --from=builder /app/public ./public
COPY --chown=node:node --from=builder /app/.next ./.next
COPY --chown=node:node --from=builder /app/node_modules ./node_modules
EXPOSE $PORT
CMD ["node_modules/.bin/next", "start"]

My docker-compose.yml:

version: "3"

services:
    nextjs:
        container_name: redcross-frontend
        ports:
            - 3000:3000
        build:
            context: ./
            dockerfile: Dockerfile
        volumes:
            - ./:/usr/src/app
        env_file:
            - .env.production

After execution docker-compose up I press CTRL+C for stopping it.
As a result in half of all cases I’ve faced with the error:
enter image description here

I tried to use dumb-init by executing this command: CMD ["dumb-init", "node_modules/.bin/next", "start"].
But I see the same error in half of all cases.

Source: Docker Questions

LEAVE A COMMENT