当前位置: 首页>>代码示例>>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;未经允许,请勿转载。