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

add kill process method when docker-compose down command #12206

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dohyunKim12
Copy link

What I did

Add kill process stage when docker-compose down command

Related issue
fixes 12205

Add killProcessesUsingExposedPorts call section in runDown func

Signed-off-by: DOHYUN KIM <[email protected]>
Signed-off-by: DOHYUN KIM <[email protected]>
Comment on lines +25 to +36
cmd := exec.Command("lsof", "-t", "-i", fmt.Sprintf(":%s", port))
output, err := cmd.Output()
if err != nil {
return fmt.Errorf("failed to find process using port %s: %v", port, err)
}

pid := strings.TrimSpace(string(output))
if pid == "" {
return nil
}

killCmd := exec.Command("kill", "-9", pid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code is not portable and won't work on Windows environment for example.
The fix proposed should work for Linux, Mac and Windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Compose is a client library, while docker engine may run on a remote machine, so this isn't the relevant place to propose such a fix. We already invoke ContainerStop API which is responsible to stop (or kill after timeout) the target container and release resources, if you found a bug with this, better report on github.com/moby/moby

Comment on lines +25 to +36
cmd := exec.Command("lsof", "-t", "-i", fmt.Sprintf(":%s", port))
output, err := cmd.Output()
if err != nil {
return fmt.Errorf("failed to find process using port %s: %v", port, err)
}

pid := strings.TrimSpace(string(output))
if pid == "" {
return nil
}

killCmd := exec.Command("kill", "-9", pid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also Compose is a client library, while docker engine may run on a remote machine, so this isn't the relevant place to propose such a fix. We already invoke ContainerStop API which is responsible to stop (or kill after timeout) the target container and release resources, if you found a bug with this, better report on github.com/moby/moby

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

Successfully merging this pull request may close these issues.

3 participants