cmd/run, pkg/podman: Stop container once the last session finishes #1213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, once a toolbox container gets started with 'podman start', as part of the 'toolbox enter' command, it doesn't stop unless the host is shut down or someone explicitly calls 'podman stop'. This becomes annoying if someone tries to remove the container because commands like 'podman rm' and such don't work without the '--force' flag, even if all active 'toolbox enter' and 'toolbox run' sessions have terminated.
A crude form of reference counting has been set up that depends on 'podman stop' failing as long there's any active 'podman exec' session left. Every invocation of 'podman exec' in 'enter' and 'run' is followed by 'podman stop', so that the container gets stopped once the last session finishes.
While this approach looks very crude at first glance, it does have the advantage of being ridiculously simple to implement. Thus, it's a lot more robust and easier to verify than setting up some custom reference counting or synchronization using other means like POSIX signals or file locks.
Based on the implementation in github.com/coreos/toolbox.
#114