How to use the docker.utils function in docker

To help you get started, we’ve selected a few docker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / version-control-tools / testing / vcttesting / docker.py View on Github external
'vct-cid',
        )
        for k in keys:
            self.state.setdefault(k, None)

        try:
            self.client = docker.DockerClient(base_url=url, tls=tls,
                                              version='auto')
            self.api_client = self.client.api
        except DockerException:
            self.client = None
            self.api_client = None
            return

        # We need API 1.22+ for some networking APIs.
        if docker.utils.compare_version('1.22',
                                        self.api_client.api_version) < 0:
            warnings.warn('Warning: unable to speak to Docker servers older '
                          'than Docker 1.10.x')
            self.client = None
            self.api_client = None
            return

        # Try to obtain a network hostname for the Docker server. We use this
        # for determining where to look for opened ports.
        # This is a bit complicated because Docker can be running from a local
        # socket or or another host via something like boot2docker.

        # This is wrong - the gateway returned is the _internal_ IP gateway for
        # running containers.  docker makes no guarantee it will be routable
        # from the host; and on MacOS this is indeed not routable.  Port mapping
        # and querying for the HostIP should be used instead (or use a sane
github docker / docker-py / tests / helpers.py View on Github external
def requires_api_version(version):
    test_version = os.environ.get(
        'DOCKER_TEST_API_VERSION', docker.constants.DEFAULT_DOCKER_API_VERSION
    )

    return pytest.mark.skipif(
        docker.utils.version_lt(test_version, version),
        reason="API version is too low (< {0})".format(version)
    )
github sivel / ansible-template-ui / ansible_template_ui / __init__.py View on Github external
def render_template():
    data = request.get_json()

    client = docker.from_env()

    repository, tag = docker.utils.parse_repository_tag(
        os.getenv('DOCKER_IMAGE', 'sivel/ansible-template-ui')
    )

    if not tag:
        tag = data.get('tag', 'latest')

    image = '%s:%s' % (repository, tag)

    try:
        client.images.pull(repository, tag=tag)

        container = client.containers.create(
            image,
            environment={
                'TEMPLATE': text.native(
                    base64.b64encode(
github docker / docker-py / docker / api / image.py View on Github external
    @utils.minimum_version('1.30')
    @utils.check_resource('image')
    def inspect_distribution(self, image, auth_config=None):
        """
        Get image digest and platform information by contacting the registry.

        Args:
            image (str): The image name to inspect
            auth_config (dict): Override the credentials that are found in the
                config for this request.  ``auth_config`` should contain the
                ``username`` and ``password`` keys to be valid.

        Returns:
            (dict): A dict containing distribution data

        Raises:
            :py:class:`docker.errors.APIError`
github TomasTomecek / sen / sen / docker_backend.py View on Github external
def __init__(self):
        self._containers = None
        self._images = None  # displayed images
        self._all_images = None  # docker images -a
        self._df = None

        kwargs = {"version": "auto"}
        kwargs.update(docker.utils.kwargs_from_env(assert_hostname=False))

        try:
            APIClientClass = docker.Client  # 1.x
        except AttributeError:
            APIClientClass = docker.APIClient  # 2.x

        try:
            self.client = APIClientClass(**kwargs)
        except docker.errors.DockerException as ex:
            raise TerminateApplication("can't establish connection to docker daemon: {0}".format(str(ex)))

        self.scratch_image = RootImage(self)
github Autodesk / pyccc / pyccc / engines.py View on Github external
def __init__(self, client=None, workingdir='/default_wdir'):
        """ Initialization:

        Args:
            client (docker.Client): a docker-py client. If not passed, we will try to create the
                client from the job's environmental varaibles
            workingdir (str): default working directory to create in the containers
        """
        if client is None:
            client = docker.Client(**docker.utils.kwargs_from_env())
        self.client = client
        self.default_wdir = workingdir
        self.hostname = self.client.base_url
github worstcase / blockade / blockade / utils.py View on Github external
def docker_run(command,
               image='ubuntu:trusty',
               network_mode='host',
               privileged=True,
               docker_client=None):

    default_client = docker.APIClient(
        **docker.utils.kwargs_from_env(assert_hostname=False)
    )
    docker_client = docker_client or default_client

    host_config = docker_client.create_host_config(
            network_mode=network_mode, privileged=privileged)

    try:
        container = docker_client.create_container(
                image=image, command=command, host_config=host_config)
    except docker.errors.NotFound:
        docker_client.pull(image)
        container = docker_client.create_container(
                image=image, command=command, host_config=host_config)

    docker_client.start(container=container.get('Id'))
github openstack / kolla-ansible / ansible / library / kolla_docker.py View on Github external
def compare_image(self, container_info=None):
        container_info = container_info or self.get_container_info()
        parse_repository_tag = docker.utils.parse_repository_tag
        if not container_info:
            return True
        new_image = self.check_image()
        current_image = container_info['Image']
        if not new_image:
            return True
        if new_image['Id'] != current_image:
            return True
        # NOTE(Jeffrey4l) when new image and the current image have
        # the same id, but the tag name different.
        elif (parse_repository_tag(container_info['Config']['Image']) !=
              parse_repository_tag(self.params.get('image'))):
            return True