Ctrl-C does not stop log4brains preview when run in Docker
francoisvdv opened this issue · 2 comments
Bug Report
Great project, thanks for your work! I am trying to run log4brains in Docker and I encounter the following. If I have time I will try to submit a PR fixing this, but for now I will submit the issue.
Description
Ctrl-C does not stop log4brains preview when run in Docker
Steps to Reproduce
- Run 'log4brains preview' in Docker with the following command:
docker run --rm -ti -v $(pwd):/workdir -p 4004:4004 thomvaill/log4brains preview
- Press ctrl-c
- The container does not stop
Expected Behavior
In step 3, log4brains and the container should stop.
Context
You can stop the container by running docker ps
and running docker stop <container id>
but this is cumbersome.
Environment
- Log4brains version: the version in Docker image (1.0.0-beta.11)
thomvaill/log4brains latest 7bb84c921b02 6 weeks ago 412MB
- Node.js version: version in Docker image
- OS and its version: version in Docker image
- Browser information: Firefox
Possible Solution
I do not have a solution right now, but maybe playing with the Docker entrypoint / cmd can fix this.
@francoisvdv according to https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md#handling-kernel-signals
Node.js was not designed to run as PID 1 which leads to unexpected behaviour when running inside of Docker. For example, a Node.js process running as PID 1 will not respond to SIGINT (CTRL-C) and similar signals. As of Docker 1.13, you can use the --init flag to wrap your Node.js process with a lightweight init system that properly handles running as PID 1.
docker run -it --init nodeYou can also include Tini directly in your Dockerfile, ensuring your process is always started with an init wrapper.
Is this the right way to solve this?
I can confirm that adding --init
to my docker run
command does fix the CTRL-C issue for me!