@@ -0,0 +1,3086 @@
+#!/usr/bin/env python3%0A%0A%22%22%22%0AWrapper for docker-py low-level client API.%0AAllow creating container and using it within %60with%60 statement.%0A%22%22%22%0A%0A# Imports%0A%0Aimport docker%0A%0A%0A# Classes%0A%0Aclass Container:%0A    %22%22%22%0A    Class to represent docker container and expose simple API to it.%0A%0A    %22%22%22%0A%0A    def __init__(self, image, command, environment=None):%0A        %22%22%22%0A        Create the container. Not the same as %60docker run%60, need to be started after the creation.%0A%0A        :param image: the image to run%0A        :type image: STRING%0A        :param command: the command to be run in the container%0A        :type command: STRING or LIST%0A        :param environment: A dictionary or a list of strings in the following format %7B%22TEST%22: %22123%22%7D or %5B%22TEST=123%22%5D.%0A        :type environment: DICT or LIST%0A        %22%22%22%0A        self.client = None%0A        self.id = None%0A        self.run(image, command, environment)%0A%0A    def __enter__(self):%0A        %22%22%22%0A        Start the container and make a %60with%60 context.%0A        %22%22%22%0A        self.start()%0A        return self%0A%0A    def __exit__(self, exc_type, exc_val, exc_tb):%0A        %22%22%22%0A        Stop the container and clean up.%0A        %22%22%22%0A        self.stop()%0A        self.remove()%0A%0A    def run(self, image, command, environment=None):%0A        %22%22%22%0A        Do real work of __init__.%0A        %22%22%22%0A        self.client = docker.APIClient()%0A        result = self.client.create_container(%0A            image,%0A            command=command,%0A            detach=True,%0A            environment=environment%0A        )%0A        self.id = result%5B'Id'%5D%0A%0A    def exec(self, command):%0A        %22%22%22%0A        Execute the command inside container cid%0A    %0A        :param str command: String representation of bash command%0A        %0A        :return: Returns a generator of output of the result of running bash command in bytes%0A        :rtype: iter%0A        %22%22%22%0A        exe = self.client.exec_create(container=self.id, cmd=command)%0A        exe_start = self.client.exec_start(exec_id=exe, stream=True)%0A%0A        return iter(exe_start)  # as iterator%0A%0A    def inspect(self):%0A        %22%22%22%0A        :return: Description of the container ans its status%0A        :rtype: DICT%0A        %22%22%22%0A        return self.client.inspect_container(self.id)%0A%0A    def start(self):%0A        %22%22%22%0A        Start the container.%0A        %22%22%22%0A        return self.client.start(self.id)%0A%0A    def stop(self):%0A        %22%22%22%0A        Stop the container.%0A        %22%22%22%0A        return self.client.stop(self.id)%0A%0A    def logs(self):%0A        %22%22%22%0A        :return: Returns a stream of the STDOUT and STDERR%0A        :rtype: iter%0A        %22%22%22%0A        return self.client.attach(self.id,%0A                                  stdout=True,%0A                                  stderr=True,%0A                                  stream=True,  # as iterator%0A                                  logs=False)%0A%0A    def kill(self):%0A        %22%22%22%0A        Kill the container.%0A        %22%22%22%0A        return self.client.kill(self.id)%0A%0A    def remove(self):%0A        %22%22%22%0A        Remove the container and associated volumes.%0A        %22%22%22%0A        return self.client.remove_container(self.id, v=True)%0A

add container class