Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add --rm=dead or --rm=always to ease systemd integration #7245
AFAIK, running a docker container 'properly' from systemd is very tricky, because of things like --rm and start/run/environment and other things. Various people have complained about this a bit, and various solutions exist -- all of which involve running a large shell script in your systemd unit file. I think I would really want the preferred way to run a container from systemd to be simple and not require shell scripting.
What about adding additional options to run --rm?
The reason something like
The 'proper' way of integrating throwaway containers with systemd would be greatly simplified, and look something like this:
Hm, the underlying daemon doesn't implement --rm? That explains why -d and --rm aren't compatible (I haven't dived into docker's source code yet).
Still, having that type of functionality available from the CLI would be desirable, as that's how one writes unit files at the moment. Each one of the actions above have equivalent shell script implementations using various cli commands. For things already interacting with docker directly via socket, I imagine it's less of a hassle to add the extra code to do these types of things.
+1 on this. I was trying to manage docker containers with supervisord, and it's like a pain in ass since it's so easy to leave dead container behind. Even you always run docker with --rm, it doesn't help at all. For example:
however, since 5050 port is already in use, so you got an error messages like this:
It looks like docker run client code didn't clean the dead container for you, simply because it encountered an error. And then supervisord tries to start the process again, it would never succeed since the dead container is not removed. You need to remove the container manually to keep the system running.
This breaks my ansible automatic deployment, I always need to clean dead container manually, this is super annoying.
In the mean time, a possible workaround is to have a script runs
I think @virtuald is right, the
It does not only breaks the promise when starting a docker with error, it also does this when you reboot the machine, and I believe there are just way too many cases
@victorlin we are running into the same frustrations managing docker containers with supervisord: https://gist.github.com/rgarcia/dfdf41844668d4cc13bc
Going to try using your script.
referenced this issue
Jan 30, 2015
Why did all work on this stall out? I followed all the links and there is a lot of discussion, a lot of PRs, etc... and it all ends with comments like "So why was this closed?"
I also share the massive frustration of
Ahh, thank you. Sometimes it's hard to navigate all the issues/pr links.
Here's my workaround in case anyone is interested in the meantime. It's a
#!/usr/bin/env python import os import sys import subprocess try: i = sys.argv.index("--name") name = sys.argv[i+1] except ValueError: name == None if "--rm" in sys.argv and name: with open(os.devnull, "w") as devnull: subprocess.call(["docker", "rm", name], stdout=devnull, stderr=devnull) # sys.argv includes the program name (this script), so we copy and replace it. # Note that the args must include "docker" as the first arg, despite it # being redundant in the execvp call. args = ["docker", "run"] + sys.argv[1:] # docker run ... os.execvp("docker", args)
Note that it only works when you use