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

docker exec should cleanup its orphaned processes when it exits #9994

Closed
wants to merge 3 commits into from

Conversation

dqminh
Copy link
Contributor

@dqminh dqminh commented Jan 9, 2015

Some background on this is at:

TLDR: docker exec process when exits can leave behind orphaned/unwanted processes, this patch put all processes belongs to a single docker exec session into its own subcgroup and removes them when the main process finishes. This will not affect processes spawned in the container and/or other exec sessions.

@SvenDowideit
Copy link
Contributor

nice - can you please add a sentence or two to this effect into the run.md - that way anyone that is curious how and why this happens will have something to refer to

I'm interested to see how (or if) users will want to start new daemon processes using docker exec

@phemmer
Copy link
Contributor

phemmer commented Jan 9, 2015

I think this should have a flag to control the behavior. While I somewhat agree with the idea in this change, I do not think it that unreasonable for some more complex applications & systems to use docker exec for lauching long running commands inside a container. Perhaps as part of some nightly maintenance scripts, to kick off a background task.

@dqminh
Copy link
Contributor Author

dqminh commented Jan 9, 2015

@phemmer @SvenDowideit in that case, would it make more sense to run each long-running process in a different docker exec -d session instead of having short-lived script launching multiple long-running daemon ?

The purpose of the patch is to prevent that exact situation as ideally an exec session should not leave orphaned process inside the PID namespace when it finishes.

@LK4D4
Copy link
Contributor

LK4D4 commented Jan 13, 2015

@dqminh I think that libcontainer was bumped and now you can rebase against master.

@SvenDowideit
Copy link
Contributor

yes, I guess docker attach $(docker exec -dit ...) makes sense, compared to docker exec -it nohup stuff - does it work that way?

yes, I realised talking to some people last night, that you might have a long running upgrade / transform task you might start with docke exec, and having it reaped due to network failure to the Docker client may make them cry too.

no-easy-answer

@SvenDowideit
Copy link
Contributor

I'd document what the PR does now, as it seems like a useful addition as is.

@dqminh
Copy link
Contributor Author

dqminh commented Jan 19, 2015

yes, I realised talking to some people last night, that you might have a long running upgrade / transform task you might start with docke exec, and having it reaped due to network failure to the Docker client may make them cry too.

ah no, it currently doesnt behave like that. The behavior of how docker exec client affects the remote exec session on the server when the client exits is currently undefined.

Starting a long running exec session with docker exec -d will work as is ( i.e, the remote exec process will not be killed if the client is killed ). This patch only affects cleanup of docker exec processes when the main process exits. For example:

# before this patch
> docker exec -it my-precious sh
/ # sleep 1000 &
/ # exit
# now there's a dangling `sleep 1000` process inside the parent container after main `sh` process exits and user has to clean it up manually

# after this patch
> docker exec -it my-precious sh
/ # sleep 1000 &
/ # exit
# main `sh` process and its `sleep 1000` child process will be stopped.

@SvenDowideit i will add some docs to cli and the HTTP api to document the new behavior for this patch.

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)
Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)

Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
execin now requires us to pass in the execin's session id so it can create
cgroups to track orphaned processes

Docker-DCO-1.1-Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com> (github: dqminh)

Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
@dqminh
Copy link
Contributor Author

dqminh commented Jan 21, 2015

Actually i think it probably makes more sense to have the cgroup setup as an optional part. Some of our users do want to launch background processes from an interactive exec session and dont want them to be shut down automatically.

I will close this and open again when it's ready.

@dqminh dqminh closed this Jan 21, 2015
@thefallentree
Copy link

@dqminh Is there followup on this PR?

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.

None yet

5 participants