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


Python containers.Container方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def __init__(self, username: str, labbook: Optional[LabBook] = None, path: Optional[str] = None,
                 override_image_name: Optional[str] = None):
        """Set up local Docker access and proceed to standard superclass init

        Args:
            username: the logged-in Gigantum username (or a special-purpose username)
            labbook: if provided, it is assumed that labbook.name and labbook.owner are populated (including from a path)
            path: (ignored if labbook is not None) a path where we can load a LabBook from
            override_image_name: should be set programmatically if we can obtain labbok owner and name, and there's no
                "override" image "tag"
        """
        self._client = get_docker_client()

        # We can populate _image_id with .build_image() or .image_available(),
        # the latter doesn't check the environment hash and is fast
        self._image_id: Optional[str] = None
        self._container: Optional[Container] = None

        ContainerOperations.__init__(self, username, labbook=labbook, path=path,
                                     override_image_name=override_image_name)

    # Manipulating images 
開發者ID:gigantum,項目名稱:gigantum-client,代碼行數:24,代碼來源:local_container.py

示例2: _create_oef_docker_image

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def _create_oef_docker_image(oef_addr_, oef_port_) -> Container:
    client = docker.from_env()

    logger.info(ROOT_DIR + "/tests/common/oef_search_pluto_scripts")
    ports = {
        "20000/tcp": ("0.0.0.0", 20000),  # nosec
        "30000/tcp": ("0.0.0.0", 30000),  # nosec
        "{}/tcp".format(oef_port_): ("0.0.0.0", oef_port_),  # nosec
    }
    volumes = {
        ROOT_DIR
        + "/tests/common/oef_search_pluto_scripts": {"bind": "/config", "mode": "rw"},
        ROOT_DIR + "/data/oef-logs": {"bind": "/logs", "mode": "rw"},
    }
    c = client.containers.run(
        "fetchai/oef-search:0.7",
        "/config/node_config.json",
        detach=True,
        ports=ports,
        volumes=volumes,
    )
    return c 
開發者ID:fetchai,項目名稱:agents-aea,代碼行數:24,代碼來源:conftest.py

示例3: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container, response_text: str) -> None:
    config_data = get_config(container)
    assert config_data["workers_per_core"] == 1
    assert config_data["host"] == "0.0.0.0"
    assert config_data["port"] == "80"
    assert config_data["loglevel"] == "info"
    assert config_data["workers"] >= 2
    assert config_data["bind"] == "0.0.0.0:80"
    logs = get_logs(container)
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text 
開發者ID:tiangolo,項目名稱:uvicorn-gunicorn-docker,代碼行數:18,代碼來源:test_package_app.py

示例4: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container) -> None:
    process_names = get_process_names(container)
    config_data = get_config(container)
    assert config_data["workers"] == 1
    assert len(process_names) == 2  # Manager + worker
    assert config_data["host"] == "127.0.0.1"
    assert config_data["port"] == "80"
    assert config_data["loglevel"] == "warning"
    assert config_data["bind"] == "127.0.0.1:80"
    assert config_data["graceful_timeout"] == 120
    assert config_data["timeout"] == 120
    assert config_data["keepalive"] == 5
    assert config_data["errorlog"] == "-"
    assert config_data["accesslog"] == "-"
    logs = get_logs(container)
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    assert "loglevel: debug" in logs
    assert "Using worker: uvicorn.workers.UvicornH11Worker" in logs 
開發者ID:tiangolo,項目名稱:uvicorn-gunicorn-docker,代碼行數:24,代碼來源:test_env_vars_2.py

示例5: test_defaults

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def test_defaults() -> None:
    name = os.getenv("NAME")
    image = f"tiangolo/uvicorn-gunicorn:{name}"
    response_text = get_response_text1()
    sleep_time = int(os.getenv("SLEEP_TIME", 1))
    remove_previous_container(client)
    container: Container = client.containers.run(
        image,
        name=CONTAINER_NAME,
        ports={"80": "8000"},
        detach=True,
        command="/start-reload.sh",
    )
    time.sleep(sleep_time)
    verify_container(container, response_text)
    container.exec_run(
        "sed -i 's|Uvicorn with Gunicorn|Uvicorn with autoreload|' /app/main.py"
    )
    new_response_text = response_text.replace(
        "Uvicorn with Gunicorn", "Uvicorn with autoreload"
    )
    time.sleep(sleep_time)
    verify_container(container, new_response_text)
    container.stop()
    container.remove() 
開發者ID:tiangolo,項目名稱:uvicorn-gunicorn-docker,代碼行數:27,代碼來源:test_defaults.py

示例6: _containers_by_role

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def _containers_by_role(self, role: Role) -> Set[Container]:
        """
        Return all containers in this cluster of a particular node type.
        """
        node_types = {
            Role.MASTER: NODE_TYPE_MASTER_LABEL_VALUE,
            Role.AGENT: NODE_TYPE_AGENT_LABEL_VALUE,
            Role.PUBLIC_AGENT: NODE_TYPE_PUBLIC_AGENT_LABEL_VALUE,
        }
        client = docker_client()
        filters = {
            'label': [
                self._cluster_id_label,
                '{key}={value}'.format(
                    key=NODE_TYPE_LABEL_KEY,
                    value=node_types[role],
                ),
            ],
        }
        return set(client.containers.list(filters=filters)) 
開發者ID:dcos,項目名稱:dcos-e2e,代碼行數:22,代碼來源:_common.py

示例7: to_node

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def to_node(self, node_representation: Container) -> Node:
        """
        Return the ``Node`` that is represented by a given ``container``.
        """
        container = node_representation
        networks = container.attrs['NetworkSettings']['Networks']
        network_name = 'bridge'
        if len(networks) != 1:
            [network_name] = list(networks.keys() - set(['bridge']))
        address = IPv4Address(networks[network_name]['IPAddress'])
        return Node(
            public_ip_address=address,
            private_ip_address=address,
            default_user=self._ssh_default_user,
            ssh_key_path=self.ssh_key_path,
            default_transport=self._transport,
        ) 
開發者ID:dcos,項目名稱:dcos-e2e,代碼行數:19,代碼來源:_common.py

示例8: loopback_sidecars_by_name

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def loopback_sidecars_by_name(name: str) -> List[Container]:
    """
    Return all loopback sidecar containers with the given sidecar ``name``.
    """
    client = docker_client()
    filters = {
        'label': [
            '{key}={value}'.format(
                key=NODE_TYPE_LABEL_KEY,
                value=NODE_TYPE_LOOPBACK_SIDECAR_LABEL_VALUE,
            ),
            '{key}={value}'.format(
                key=SIDECAR_NAME_LABEL_KEY,
                value=name,
            ),
        ],
    }
    return list(client.containers.list(filters=filters)) 
開發者ID:dcos,項目名稱:dcos-e2e,代碼行數:20,代碼來源:_loopback_sidecars.py

示例9: run

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def run(self, image: str,
            command: str = None,
            environment: dict = None,
            ports: dict = None,
            detach: bool = False,
            stdout: bool = True,
            stderr: bool = False,
            remove: bool = False, **kwargs) -> Container:
        return self.client.containers.run(image,
                                          command=command,
                                          stdout=stdout,
                                          stderr=stderr,
                                          remove=remove,
                                          detach=detach,
                                          environment=environment,
                                          ports=ports,
                                          **kwargs) 
開發者ID:testcontainers,項目名稱:testcontainers-python,代碼行數:19,代碼來源:docker_client.py

示例10: start

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def start(self):
        print("")
        print("{} {}".format(crayons.yellow("Pulling image"),
                             crayons.red(self.image)))
        with blindspin.spinner():
            docker_client = self.get_docker_client()
            self._container = docker_client.run(self.image,
                                                command=self._command,
                                                detach=True,
                                                environment=self.env,
                                                ports=self.ports,
                                                name=self._name,
                                                volumes=self.volumes,
                                                **self._kargs
                                                )
        print("")
        print("Container started: ",
              crayons.yellow(self._container.short_id, bold=True))
        return self 
開發者ID:testcontainers,項目名稱:testcontainers-python,代碼行數:21,代碼來源:container.py

示例11: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container, response_text: str) -> None:
    response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text
    config_data = get_config(container)
    assert config_data["workers_per_core"] == 2
    assert config_data["host"] == "0.0.0.0"
    assert config_data["port"] == "80"
    assert config_data["loglevel"] == "info"
    assert config_data["workers"] > 2
    assert config_data["bind"] == "0.0.0.0:80"
    logs = get_logs(container)
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    ) 
開發者ID:tiangolo,項目名稱:meinheld-gunicorn-flask-docker,代碼行數:18,代碼來源:test_defaults.py

示例12: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container, response_text: str) -> None:
    response = requests.get("http://127.0.0.1:8080")
    assert response.text == response_text
    nginx_config = get_nginx_config(container)
    assert "client_max_body_size 0;" not in nginx_config
    assert "worker_processes 2;" in nginx_config
    assert "listen 8080;" in nginx_config
    assert "worker_connections 2048;" in nginx_config
    assert "worker_rlimit_nofile;" not in nginx_config
    assert "daemon off;" in nginx_config
    assert "include uwsgi_params;" in nginx_config
    assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config
    assert "keepalive_timeout  300;" in nginx_config
    logs = get_logs(container)
    assert "getting INI configuration from /app/uwsgi.ini" in logs
    assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs
    assert "ini = /app/uwsgi.ini" in logs
    assert "ini = /etc/uwsgi/uwsgi.ini" in logs
    assert "socket = /tmp/uwsgi.sock" in logs
    assert "chown-socket = nginx:nginx" in logs
    assert "chmod-socket = 664" in logs
    assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs
    assert "need-app = true" in logs
    assert "die-on-term = true" in logs
    assert "show-config = true" in logs
    assert "wsgi-file = /app/main.py" in logs
    assert "processes = 16" in logs
    assert "cheaper = 2" in logs
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    assert "spawned uWSGI master process" in logs
    assert "spawned uWSGI worker 1" in logs
    assert "spawned uWSGI worker 2" in logs
    assert "spawned uWSGI worker 3" not in logs
    assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs
    assert "success: nginx entered RUNNING state, process has stayed up for" in logs
    assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs 
開發者ID:tiangolo,項目名稱:uwsgi-nginx-docker,代碼行數:42,代碼來源:test_custom_nginx_app.py

示例13: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container, response_text: str) -> None:
    response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text
    nginx_config = get_nginx_config(container)
    assert "client_max_body_size 0;" in nginx_config
    assert "worker_processes 1;" in nginx_config
    assert "listen 80;" in nginx_config
    assert "worker_connections 1024;" in nginx_config
    assert "worker_rlimit_nofile;" not in nginx_config
    assert "daemon off;" in nginx_config
    assert "include uwsgi_params;" in nginx_config
    assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config
    logs = get_logs(container)
    assert "getting INI configuration from /app/uwsgi.ini" in logs
    assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs
    assert "ini = /app/uwsgi.ini" in logs
    assert "ini = /etc/uwsgi/uwsgi.ini" in logs
    assert "socket = /tmp/uwsgi.sock" in logs
    assert "chown-socket = nginx:nginx" in logs
    assert "chmod-socket = 664" in logs
    assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs
    assert "need-app = true" in logs
    assert "die-on-term = true" in logs
    assert "show-config = true" in logs
    assert "wsgi-file = /app/main.py" in logs
    assert "processes = 16" in logs
    assert "cheaper = 2" in logs
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert (
        "Running inside /app/prestart.sh, you could add migrations to this file" in logs
    )
    assert "spawned uWSGI master process" in logs
    assert "spawned uWSGI worker 1" in logs
    assert "spawned uWSGI worker 2" in logs
    assert "spawned uWSGI worker 3" not in logs
    assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs
    assert "success: nginx entered RUNNING state, process has stayed up for" in logs
    assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs 
開發者ID:tiangolo,項目名稱:uwsgi-nginx-docker,代碼行數:41,代碼來源:test_app_with_installs.py

示例14: verify_container

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def verify_container(container: Container, response_text: str) -> None:
    response = requests.get("http://127.0.0.1:8000")
    assert response.text == response_text
    nginx_config = get_nginx_config(container)
    assert "client_max_body_size 0;" in nginx_config
    assert "worker_processes 1;" in nginx_config
    assert "listen 8080;" in nginx_config
    assert "worker_connections 1024;" in nginx_config
    assert "worker_rlimit_nofile;" not in nginx_config
    assert "daemon off;" in nginx_config
    assert "include uwsgi_params;" in nginx_config
    assert "uwsgi_pass unix:///tmp/uwsgi.sock;" in nginx_config
    logs = get_logs(container)
    assert "getting INI configuration from /application/custom_app/uwsgi.ini" in logs
    assert "getting INI configuration from /etc/uwsgi/uwsgi.ini" in logs
    assert "ini = /application/custom_app/uwsgi.ini" in logs
    assert "ini = /etc/uwsgi/uwsgi.ini" in logs
    assert "socket = /tmp/uwsgi.sock" in logs
    assert "chown-socket = nginx:nginx" in logs
    assert "chmod-socket = 664" in logs
    assert "hook-master-start = unix_signal:15 gracefully_kill_them_all" in logs
    assert "need-app = true" in logs
    assert "die-on-term = true" in logs
    assert "show-config = true" in logs
    assert "wsgi-file = /application/custom_app/main.py" in logs
    assert "processes = 16" in logs
    assert "cheaper = 2" in logs
    assert "Checking for script in /app/prestart.sh" in logs
    assert "Running script /app/prestart.sh" in logs
    assert "custom prestart.sh running" in logs
    assert "spawned uWSGI master process" in logs
    assert "spawned uWSGI worker 1" in logs
    assert "spawned uWSGI worker 2" in logs
    assert "spawned uWSGI worker 3" not in logs
    assert 'running "unix_signal:15 gracefully_kill_them_all" (master-start)' in logs
    assert "success: nginx entered RUNNING state, process has stayed up for" in logs
    assert "success: uwsgi entered RUNNING state, process has stayed up for" in logs 
開發者ID:tiangolo,項目名稱:uwsgi-nginx-docker,代碼行數:39,代碼來源:test_app_and_env_vars.py

示例15: get_logs

# 需要導入模塊: from docker.models import containers [as 別名]
# 或者: from docker.models.containers import Container [as 別名]
def get_logs(container: Container) -> str:
    logs = container.logs()
    return logs.decode("utf-8") 
開發者ID:tiangolo,項目名稱:uwsgi-nginx-docker,代碼行數:5,代碼來源:utils.py


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