- ciddir = tempfile.mkdtemp()
- cidfilepath = os.path.join(ciddir, "cidfile")
- self.docker_proc = subprocess.Popen(["docker", "run",
- "--cidfile=%s" % (cidfilepath),
- "--publish=%i:80" % (self.port),
- "--volume=%s:/mnt:ro" % self.mountdir,
- docker_image])
- self.cid = None
- while self.cid is None and self.docker_proc.poll() is None:
- try:
- with open(cidfilepath) as cidfile:
- self.cid = cidfile.read().strip()
- except IOError as e:
- # XXX check for ENOENT
- pass
-
- try:
- if os.path.exists(cidfilepath):
- os.unlink(cidfilepath)
- os.rmdir(ciddir)
- except OSError:
- pass
+ self.cid = subprocess.check_output(["docker", "run",
+ "--detach=true",
+ "--publish=%i:80" % (self.port),
+ "--volume=%s:/mnt:ro" % self.mountdir,
+ docker_image]).strip()