Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When running examples in docker - can't kill'em using CTRL+C #3667

Closed
lakruzz opened this issue Jun 10, 2018 · 5 comments
Closed

When running examples in docker - can't kill'em using CTRL+C #3667

lakruzz opened this issue Jun 10, 2018 · 5 comments
Labels

Comments

@lakruzz
Copy link

lakruzz commented Jun 10, 2018

I'm running node and npm from a docker container - without actually installing the tools locally. The following works fine:

git clone https://github.com/expressjs/express.git
cd expressjs
docker run -it --rm -p 3000:3000 -v $(pwd):/app:rw -w /app node:10  npm install
docker run -it --rm -p 3000:3000 -v $(pwd):/app:rw -w /app node:10  node examples/mvc/

(now browse to port 3000 on your docker host IP)

However, as discussed in node/issues#4182 hitting <CTRL>+C doesn't stop the process running in the docker host, the docker host receives it and passes it on (that's what the -i + -t switches to docker run does) but the express server ignores it.

Consequently the behaviour is different from running the same example with a native node installation:

...
node examples/mvc/

Adding the following snippet to (in this example to expressjs/examples/mvc/index.js solves the issue:

// Some plumbing that's required if the process is running inside a docker
// container and you want to be able to kill it from the outside using CTRL+C
process.on('SIGINT', function() {
    process.exit();
});
@dougwilson
Copy link
Contributor

dougwilson commented Jun 10, 2018

This is an issue starting processes in Linux as PID 1. You'll run into this issue all over. The correct solution is to actually run your docker image so ctrl c works as expected instead of every program changing.

Include --pod=host in your docker run args.

@lakruzz
Copy link
Author

lakruzz commented Jun 10, 2018

@dougwilson

Include --pod=host in your docker run args.

...that would be --pid host ...not --pod=host

So all in all:

docker run -it --rm -p 3000:3000 --pid host -v $(pwd):/app:rw -w /app node:10  node examples/mvc/

Does exactly what I want.

Thanks @dougwilson I absolutely agree that this is the right approach.

@dougwilson
Copy link
Contributor

Glad it worked for you. I have always had the equal sign there and Docker's own documentation shows using the equal sign. Not sure why it doesn't work for you. You may want to get Docker to fix their docs at the very least.

From https://docs.docker.com/engine/reference/run/

Use the following command to run htop inside a container:

$ docker run -it --rm --pid=host myhtop

@lakruzz
Copy link
Author

lakruzz commented Jun 10, 2018

It's not the equal sign, that's just preference in style. It's the o

The switch is --pid not --pod

Just clarifying the spelling mistake that snug in.

All is good. Thanks!

@dougwilson
Copy link
Contributor

Oooh, sorry! Since you didn't say what you changed and you changed more than one thing and I was only expecting one change, I was just assuming the one change you made was the first one that caught my eye.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants