當前位置: 首頁>>代碼示例>>Python>>正文


Python docker.sock方法代碼示例

本文整理匯總了Python中docker.sock方法的典型用法代碼示例。如果您正苦於以下問題:Python docker.sock方法的具體用法?Python docker.sock怎麽用?Python docker.sock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docker的用法示例。


在下文中一共展示了docker.sock方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __get_socket_file

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def __get_socket_file(self):
        """Gets the Docker API socket file and validates that it is a UNIX socket
        """
        # make sure the API socket exists and is a valid socket
        api_socket = self._config.get("api_socket")
        try:
            st = os.stat(api_socket)
            if not stat.S_ISSOCK(st.st_mode):
                raise Exception()
        except Exception:
            raise Exception(
                "The file '%s' specified by the 'api_socket' configuration option does not exist or is not a socket.\n\tPlease make sure you have mapped the docker socket from the host to this container using the -v parameter.\n\tNote: Due to problems Docker has mapping symbolic links, you should specify the final file and not a path that contains a symbolic link, e.g. map /run/docker.sock rather than /var/run/docker.sock as on many unices /var/run is a symbolic link to the /run directory."
                % api_socket
            )

        return api_socket 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:18,代碼來源:docker_monitor.py

示例2: _get_docker_server_api_version

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def _get_docker_server_api_version() -> str:
    """Retrieve the Docker server API version. """

    socket_path = '/var/run/docker.sock'
    if not os.path.exists(socket_path):
        raise ValueError('No docker.sock on machine (is a Docker server installed?)')

    socket_connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    socket_connection.connect(socket_path)
    socket_connection.send(b'GET http://*/version HTTP/1.1\r\nHost: *\r\n\r\n')

    response_data = socket_connection.recv(4000)
    content_lines = response_data.decode().split('\r\n')

    version_dict = json.loads(content_lines[-1])
    if 'ApiVersion' not in version_dict.keys():
        raise ValueError('ApiVersion not in Docker version config data')
    else:
        return version_dict['ApiVersion'] 
開發者ID:gigantum,項目名稱:gigantum-client,代碼行數:21,代碼來源:docker.py

示例3: _get_container_kwargs

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def _get_container_kwargs(self, step, img, name):
        args = {
            "image": img,
            "command": list(step.args),
            "name": name,
            "volumes": [
                f"{self._config.workspace_dir}:/workspace",
                "/var/run/docker.sock:/var/run/docker.sock",
            ],
            "working_dir": step.dir if step.dir else "/workspace",
            "environment": self._prepare_environment(step),
            "entrypoint": step.runs if step.runs else None,
            "detach": not self._config.pty,
            "tty": self._config.pty,
            "stdin_open": self._config.pty,
        }

        self._update_with_engine_config(args)

        log.debug(f"container args: {pu.prettystr(args)}\n")

        return args 
開發者ID:getpopper,項目名稱:popper,代碼行數:24,代碼來源:runner_host.py

示例4: stop

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def stop(self, wait_on_join=True, join_timeout=5):
        if self.__client and self.__logs and self.__logs.response:
            sock = self.__client._get_raw_response_socket(self.__logs.response)
            if sock:
                sock.shutdown(socket.SHUT_RDWR)
        self.__thread.stop(wait_on_join=wait_on_join, join_timeout=join_timeout) 
開發者ID:scalyr,項目名稱:scalyr-agent-2,代碼行數:8,代碼來源:docker_monitor.py

示例5: _init_client

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def _init_client(self):
        """Init docker client.

        Make sure that docker service to be published under the
        ``unix://var/run/docker.sock`` unix socket.

        Use auto for version in order to allow docker client to automatically
        figure out the server version.
        """
        if self._client:
            return
        self._client = docker.Client(
            base_url='unix://var/run/docker.sock', version='auto') 
開發者ID:SatelliteQE,項目名稱:airgun,代碼行數:15,代碼來源:browser.py

示例6: get_client

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def get_client():
    """
    Set DOCKER_HOST (and probably DOCKER_TLS_VERIFY and DOCKER_CERT_PATH) to connect to a docker instance through TCP.
    Leave DOCKER_HOST unset and it will use the default, typically unix:/var/run/docker.sock

    It also needs to know how to connect to ports on the docker container after creating it.
    Set DOCKER_NET_HOST to provide an IP address to connect to the VNC ports on
    otherwise if DOCKER_HOST has a hostname, it will connect to the VNC ports using that name.
    otherwise it connects using localhost
    """
    info = {}
    host = os.environ.get('DOCKER_HOST')
    net_host = os.environ.get('DOCKER_NET_HOST')

    client_api_version = os.environ.get('DOCKER_API_VERSION')
    if not client_api_version:
        client_api_version = "auto"

    # IP to use for started containers
    if net_host:
        info['host'] = net_host
    elif host:
        info['host'] = urlparse.urlparse(host).netloc.split(':')[0]
    else:
        info['host'] = 'localhost'

    verify = os.environ.get('DOCKER_TLS_VERIFY') == '1'
    if verify: # use TLS
        assert_hostname = None
        cert_path = os.environ.get('DOCKER_CERT_PATH')
        if cert_path:
            client_cert = (os.path.join(cert_path, 'cert.pem'), os.path.join(cert_path, 'key.pem'))
            ca_cert = os.path.join(cert_path, 'ca.pem')
        else:
            client_cert = ca_cert = None

        tls_config = docker.tls.TLSConfig(
            client_cert=client_cert,
            ca_cert=ca_cert,
            verify=verify,
            assert_hostname=assert_hostname,
        )
        return docker.Client(base_url=host, tls=tls_config, version=client_api_version), info
    else:
        return docker.Client(base_url=host, version=client_api_version), info 
開發者ID:openai,項目名稱:universe,代碼行數:47,代碼來源:docker_remote.py

示例7: get_docker_client

# 需要導入模塊: import docker [as 別名]
# 或者: from docker import sock [as 別名]
def get_docker_client():
    """Get the user's docker client.

    Raises:
        AppstartAbort: If there was an error in connecting to the
            Docker Daemon.

    Returns:
        (docker.Client) a docker client that can be used to manage
        containers and images.
    """
    host = os.environ.get('DOCKER_HOST')
    cert_path = os.environ.get('DOCKER_CERT_PATH')
    tls_verify = int(os.environ.get('DOCKER_TLS_VERIFY', 0))

    params = {}
    if host:
        params['base_url'] = (host.replace('tcp://', 'https://')
                              if tls_verify else host)
    elif sys.platform.startswith('linux'):
        # if this is a linux user, the default value of DOCKER_HOST
        # should be the unix socket.  first check if the socket is
        # valid to give a better feedback to the user.
        if os.path.exists(LINUX_DOCKER_HOST):
            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            try:
                sock.connect(LINUX_DOCKER_HOST)
                params['base_url'] = 'unix://' + LINUX_DOCKER_HOST
            except socket.error:
                get_logger().warning('Found a stale '
                                     '/var/run/docker.sock, '
                                     'did you forget to start '
                                     'your docker daemon?')
            finally:
                sock.close()

    if tls_verify and cert_path:
        # assert_hostname=False is needed for boot2docker to work with
        # our custom registry.
        params['tls'] = docker.tls.TLSConfig(
            client_cert=(os.path.join(cert_path, 'cert.pem'),
                         os.path.join(cert_path, 'key.pem')),
            ca_cert=os.path.join(cert_path, 'ca.pem'),
            verify=True,
            ssl_version=ssl.PROTOCOL_TLSv1,
            assert_hostname=False)

    # pylint: disable=star-args
    client = ClientWrapper(version=DOCKER_API_VERSION,
                           timeout=TIMEOUT_SECS,
                           **params)
    try:
        client.ping()
    except requests.exceptions.ConnectionError as excep:
        raise AppstartAbort('Failed to connect to Docker '
                            'Daemon due to: {0}'.format(excep.message))
    return client 
開發者ID:GoogleCloudPlatform,項目名稱:appstart,代碼行數:59,代碼來源:utils.py


注:本文中的docker.sock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。