How to use the docker.DockerClient 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 rycus86 / webhook-proxy / tests / integrationtest_helper.py View on Github external
def dind_client(cls, container):
        return docker.DockerClient('tcp://%s:%s' % (cls.DIND_HOST, cls.dind_port(container)),
                                   version='auto')
github rycus86 / webhook-proxy / tests / integrationtest_helper.py View on Github external
def setUpClass(cls):
        assert cls.DIND_VERSION is not None

        cls.local_client = docker.DockerClient(os.environ.get('DOCKER_ADDRESS'))

        assert cls.local_client.version() is not None

        cls.build_project()

        cls.dind_container = cls.start_dind_container()

        cls.remote_client = cls.dind_client(cls.dind_container)

        cls.prepare_images('webhook-testing')
github fastlane-queue / fastlane / fastlane / worker / docker / pool.py View on Github external
def __init_clients(self):
        for regex, docker_hosts, max_running in self.docker_hosts:
            client_list = []
            clients = (regex, client_list)
            self.clients_per_regex.append(clients)
            self.max_running[regex] = max_running

            for address in docker_hosts:
                host, port = address.split(":")
                docker_client = docker.DockerClient(base_url=address)
                self.clients[address] = (host, int(port), docker_client)
                client_list.append((host, int(port), docker_client))
github ansibleplaybookbundle / ansible-playbook-bundle / src / apb / engine.py View on Github external
if is_minishift():
        cert_path = os.environ.get('DOCKER_CERT_PATH')
        docker_host = os.environ.get('DOCKER_HOST')
        if docker_host is None or cert_path is None:
            raise Exception("Attempting to target minishift, but missing required \
                            env vars. Try running: \"eval $(minishift docker-env)\"")
        client_cert = os.path.join(cert_path, 'cert.pem')
        client_key = os.path.join(cert_path, 'key.pem')
        ca_cert = os.path.join(cert_path, 'ca.pem')
        tls = docker.tls.TLSConfig(
            ca_cert=ca_cert,
            client_cert=(client_cert, client_key),
            verify=True,
            assert_hostname=False
        )
        client = docker.DockerClient(tls=tls, base_url=docker_host, version='auto')
    else:
        client = docker.DockerClient(base_url='unix://var/run/docker.sock', version='auto')
    return client
github dockupdater / dockupdater / pyouroboros / dockerclient.py View on Github external
raise ValueError

                for cert_file in cert_paths['cert_files'].values():
                    if not isfile(cert_file):
                        self.logger.error('%s does not exist', cert_file)
                        raise ValueError

                tls_config = tls.TLSConfig(
                    ca_cert=cert_paths['cert_files']['ca_crt'],
                    verify=cert_paths['cert_files']['ca_crt'] if self.config.docker_tls_verify else False,
                    client_cert=(cert_paths['cert_files']['client_cert'], cert_paths['cert_files']['client_key'])
                )
                client = DockerClient(base_url=self.socket, tls=tls_config)
            except ValueError:
                self.logger.error('Invalid Docker TLS config for %s, reverting to unsecured', self.socket)
                client = DockerClient(base_url=self.socket)
        else:
            client = DockerClient(base_url=self.socket)

        return client
github ParadropLabs / Paradrop / paradrop / daemon / paradrop / core / container / dockerapi.py View on Github external
def getBridgeGateway():
    """
    Look up the gateway IP address for the docker bridge network.

    This is the docker0 IP address; it is the IP address of the host from the
    chute's perspective.
    """
    client = docker.DockerClient(base_url="unix://var/run/docker.sock", version='auto')

    network = client.networks.get("bridge")
    for config in network.attrs['IPAM']['Config']:
        if 'Gateway' in config:
            return config['Gateway']

    # Fall back to a default if we could not find it.  This address will work
    # in most places unless Docker changes to use a different address.
    out.warn('Could not find bridge gateway, using default')
    return '172.17.0.1'
github google / gvisor / benchmarks / harness / tunnel_dispatcher.py View on Github external
def get_docker_client(self):
    """Returns a docker client for this Tunnel."""
    return docker.DockerClient(base_url="unix:/" + self._filename)
github glzjin / CTFd-Whale / redis_utils.py View on Github external
def init_redis_port_sets(self):
        configs = DBUtils.get_all_configs()

        self.redis_client.delete(self.global_port_key)
        self.redis_client.delete(self.global_network_key)

        containers = DBUtils.get_all_container()
        used_port_list = []
        for container in containers:
            if container.port != 0:
                used_port_list.append(container.port)
        for port in range(int(configs.get("frp_direct_port_minimum", 29000)), int(configs.get("frp_direct_port_maximum", 28000)) + 1):
            if port not in used_port_list:
                self.add_available_port(port)

        client = docker.DockerClient(base_url=configs.get("docker_api_url"))
        docker_subnet = configs.get("docker_subnet", "174.1.0.0/16")
        try:
            docker_subnet = unicode(docker_subnet)
        except:
            pass
        docker_subnet_new_prefix = int(configs.get("docker_subnet_new_prefix", "24"))

        exist_networks = []
        available_networks = []

        for network in client.networks.list(filters={'label': 'prefix'}):
            exist_networks.append(str(network.attrs['Labels']['prefix']))

        for network in list(ipaddress.ip_network(docker_subnet).subnets(new_prefix=docker_subnet_new_prefix)):
            if str(network) not in exist_networks:
                available_networks.append(str(network))
github DistributedSystemsGroup / zoe / zoe_master / backends / swarm / api_client.py View on Github external
import docker.errors
import docker.utils
import docker.models.containers

import requests.exceptions

from zoe_lib.config import get_conf
from zoe_lib.state import Service, VolumeDescriptionHostPath
from zoe_master.stats import ClusterStats, NodeStats
from zoe_master.backends.service_instance import ServiceInstance
from zoe_master.exceptions import ZoeException, ZoeNotEnoughResourcesException

log = logging.getLogger(__name__)

try:
    docker.DockerClient()
except AttributeError:
    log.error('Docker package does not have the DockerClient attribute')
    raise ImportError('Wrong Docker library version')


def zookeeper_swarm(zk_server_list: str, path='/docker') -> str:
    """
    Given a Zookeeper server list, find the currently active Swarm master.
    :param zk_server_list: Zookeeper server list
    :param path: Swarm path in Zookeeper
    :return: Swarm master connection string
    """
    path += '/docker/swarm/leader'
    zk_client = KazooClient(hosts=zk_server_list)
    zk_client.start()
    master, stat_ = zk_client.get(path)
github salesforce / hassh / python / hasshGen / hasshgen.py View on Github external
def main():
    """Intake arguments from the user to build docker images and initiate SSH
    connections for generating client HASSHs"""
    args = parse_cmd_args()
    tag_id = 0
    tag_name = "hasshgen:{img}{id}"
    client = docker.DockerClient(
                base_url='unix://var/run/docker.sock',
                version='auto')

    if args.input_file:
        with open(args.input_file) as file:
            input_list = json.load(file)
        # Run hassh.py
        proc = None
        if args.fingerprint and not proc:
            proc = Popen(args.cmd, shell=True)
            time.sleep(1)
        for record in input_list:
            # Find the Dockerfile
            if record['image'] in ('debian', 'ubuntu'):
                docker_file = "{}/Dockerfile.debian".format(DOCKERFILE_DIR)
            elif record['image'] in ('centos', 'fedora'):