Skip to content

Instantly share code, notes, and snippets.

@Mic92
Last active October 26, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/d562353960056aba426a3f529dc6b044 to your computer and use it in GitHub Desktop.
Save Mic92/d562353960056aba426a3f529dc6b044 to your computer and use it in GitHub Desktop.
Use docker + python for reproducible benchmarks
from docker import Client
class Container():
def __init__(self, **kwargs):
self.api = Client()
self.container_args = kwargs
def stats(self):
s = next(self.api.stats(self.id))
return json.loads(s.decode("utf-8"))
def __enter__(self):
self.id = self.api.create_container(**self.container_args).get("Id")
self.api.start(container=self.id)
data = self.api.inspect_container(self.id)
self.ip = data["NetworkSettings"]["IPAddress"]
return self
def __exit__(self, type, value, tb):
self.api.stop(container=self.id)
self.api.remove_container(container=self.id)
with Container(image='influxdb:alpine', ports=[8083, 8086]) as container:
before = container.stats()
# do work
after = container.stats()
# before and after contain ressource statistics of the container
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment