'docker: can not start xvfb-run with docker run, but can start with docker exec -it

I'm trying to run a node app with xvfb-run, here is my Dockerfile

FROM node:lts-alpine

RUN apk --no-cache upgrade && apk add --no-cache chromium coreutils xvfb xvfb-run

ENV CHROME_BIN="/usr/bin/chromium-browser"\
  PUPPETEER_SKIP_CHROMIUM_DOWNLOAD="true" \
  UPLOAD_ENV="test"

WORKDIR /app

COPY  package.json .
COPY  .npmrc .

RUN npm install

COPY . .

# EXPOSE 9999

ENTRYPOINT xvfb-run -a npm run dev

I can successfully build the image, but when I run it with docker run, it gets stuck without any log

enter image description here

But when I open an interactive shell and run the ENTRYPOINT command, it works...

enter image description here

How do I fix it?



Solution 1:[1]

You should add --init to docker run, for example:

docker run --init --rm -it $IMAGE$ xvfb-run $COMMAND$

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 BaiJiFeiLong