question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Intermediate) If running the docker image in foreground, sending a kill signal doesn't stop the container

See original GitHub issue

To recreate the problem that exists today:

  • run docker pull supertokens/supertokens-mysql:2.4
  • Start the docker image in foreground: docker run -p 3567:3567 supertokens/supertokens-mysql:2.4
  • Wait for it to start… It should display Started SuperTokens on 0.0.0.0:3567 with PID: <some PID>
  • Now send the kill signal (Ctrl + C / Z on a Mac)

At this point, the Java process in the docker process should stop and the docker process itself should quit. However, that does not happen.

The docker file for the above image can be found in this repo. Please feel free to fork that as well.

As some extra info:

  • if not using docker (manually installing it on your system), sending the kill signal does stop the running process.
  • In the Java code (this repo), in Main.java, there is a function that registers a shutdown hook.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
Fabricio20commented, Oct 5, 2020

Hey, answering your questions:

resulting CLI script has null instead of what’s in this file

I’ll look into it later today, it should automatically be shaded by gradle however.

The if [ -f /.dockerenv ]; then checks if the script is running in the docker container, however, I’m not sure if this is the recommended way of doing so.

According to this SO answer it seems like the preferred way would be to check cgroup since .dockerenv could be removed at any moment (read about .dockerinit).

If one runs the docker container in interactive mode, and then starts supertokens, it causes all sorts of problems.

What kind of issues are you experiencing? This should trap the sigs sent to bash and recreate them as a kill command for the child’s pid. (So even if starting manually this should have the same behaviour).

The Windows version of the script can remain exactly the same since the docker image is never going to be on Windows OS.

Windows script shouldn’t have been changed, just repackaged it on resources for the sake of consistency.

0reactions
rishabhpoddarcommented, Oct 6, 2020

Thank you @Fabricio20 . I’ll test with the docker image once again and let you know what happens 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trapping signals in Docker containers | by Grigorii Chudnov
A docker command `docker kill` used to send a signal to the main process inside a container. Usage: docker kill [OPTIONS] CONTAINER [CONTAINER.....
Read more >
"docker run" cannot be killed with ctrl+c
Docker runs the script with /bin/sh -c 'command' . This intermediate script gets the SIGTERM, but doesn't send it to the running server...
Read more >
Docker, Java, Signals and Pid 1 - no42
So when you issue the command kill <pid> you send a SIGTERM to a process. ... and just run it in a Java...
Read more >
Why Does My Docker Container Stop? - Tutorial Works
This happens if you run a foreground container (using docker run ), and then press Ctrl+C when the program is running. When this...
Read more >
Chapter 5. Working with containers Red Hat Enterprise Linux 8
The podman stop command sends a SIGTERM signal to terminate a running container. If the container does not stop after a defined period...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found