本文整理汇总了Python中docker.client方法的典型用法代码示例。如果您正苦于以下问题:Python docker.client方法的具体用法?Python docker.client怎么用?Python docker.client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker
的用法示例。
在下文中一共展示了docker.client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_defaults
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_defaults() -> None:
name = os.getenv("NAME")
image = f"tiangolo/uvicorn-gunicorn-fastapi:{name}"
response_text = get_response_text1()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
container = client.containers.run(
image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例2: test_package_app_config
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_package_app_config() -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
test_path = Path(__file__)
path = test_path.parent / "package_app_config"
dockerfile_path = path / dockerfile
dockerfile_path.write_text(dockerfile_content)
client.images.build(path=str(path), dockerfile=dockerfile, tag=IMAGE_NAME)
container = client.containers.run(
IMAGE_NAME, name=CONTAINER_NAME, ports={"8000": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例3: test_package_app
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_package_app() -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
test_path = Path(__file__)
path = test_path.parent / "package_app"
dockerfile_path = path / dockerfile
dockerfile_path.write_text(dockerfile_content)
client.images.build(path=str(path), dockerfile=dockerfile, tag=IMAGE_NAME)
container = client.containers.run(
IMAGE_NAME, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例4: test_package_app_sub_config
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_package_app_sub_config() -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
test_path = Path(__file__)
path = test_path.parent / "package_app_sub_config"
dockerfile_path = path / dockerfile
dockerfile_path.write_text(dockerfile_content)
client.images.build(path=str(path), dockerfile=dockerfile, tag=IMAGE_NAME)
container = client.containers.run(
IMAGE_NAME, name=CONTAINER_NAME, ports={"8000": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例5: test_simple_app
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_simple_app() -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
test_path = Path(__file__)
path = test_path.parent / "simple_app"
dockerfile_path = path / dockerfile
dockerfile_path.write_text(dockerfile_content)
client.images.build(path=str(path), dockerfile=dockerfile, tag=IMAGE_NAME)
container = client.containers.run(
IMAGE_NAME, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例6: test_defaults
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [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 = client.containers.run(
image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例7: test_defaults
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [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()
示例8: docker_client
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def docker_client() -> DockerClient:
"""
Return a Docker client.
"""
try:
return docker.from_env(version='auto')
except docker.errors.DockerException:
message = (
'Error: Cannot connect to Docker.\n'
'Make sure that Docker is installed and running, '
'and that you can run "docker ps".\n'
'If "sudo docker ps" works, try following the instructions at '
'https://docs.docker.com/install/linux/linux-postinstall/.'
)
click.echo(message, err=True)
sys.exit(1)
示例9: _containers_by_role
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [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))
示例10: test_defaults
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_defaults() -> None:
name = os.getenv("NAME")
image = f"tiangolo/uvicorn-gunicorn-starlette:{name}"
response_text = get_response_text1()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
container = client.containers.run(
image, name=CONTAINER_NAME, ports={"80": "8000"}, detach=True
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例11: test_custom_app
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_custom_app(environment: Dict[str, str], prestart_str: str) -> None:
name = os.getenv("NAME", "")
dockerfile_content = generate_dockerfile_content(name)
dockerfile = "Dockerfile"
response_text = get_response_text2()
sleep_time = int(os.getenv("SLEEP_TIME", 1))
remove_previous_container(client)
test_path = Path(__file__)
path = test_path.parent / "custom_app"
dockerfile_path = path / dockerfile
dockerfile_path.write_text(dockerfile_content)
client.images.build(path=str(path), dockerfile=dockerfile, tag=IMAGE_NAME)
container = client.containers.run(
IMAGE_NAME,
name=CONTAINER_NAME,
environment=environment,
ports={"80": "8000"},
detach=True,
)
time.sleep(sleep_time)
verify_container(container, response_text, prestart_str)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text, prestart_str)
container.stop()
container.remove()
示例12: test_env_vars_1
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_env_vars_1() -> 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 = client.containers.run(
image,
name=CONTAINER_NAME,
environment={
"WORKERS_PER_CORE": 2,
"PORT": "8000",
"LOG_LEVEL": "warning",
"GRACEFUL_TIMEOUT": "20",
"TIMEOUT": "20",
"KEEP_ALIVE": "20",
"ACCESS_LOG": "",
"ERROR_LOG": "",
},
ports={"8000": "8000"},
detach=True,
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例13: test_env_bind
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_env_bind() -> 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 = client.containers.run(
image,
name=CONTAINER_NAME,
environment={
"BIND": "0.0.0.0:8080",
"HOST": "127.0.0.1",
"PORT": "9000",
"MAX_WORKERS": "1",
},
ports={"8080": "8000"},
detach=True,
)
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
# Test that everything works after restarting too
container.start()
time.sleep(sleep_time)
verify_container(container, response_text)
container.stop()
container.remove()
示例14: test_env_vars_1
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_env_vars_1() -> 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 = client.containers.run(
image,
name=CONTAINER_NAME,
environment={"PORT": "8000", "LOG_LEVEL": "debug"},
ports={"8000": "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()
示例15: test_default_config
# 需要导入模块: import docker [as 别名]
# 或者: from docker import client [as 别名]
def test_default_config(monkeypatch):
def docker_api_version(self):
return '1.37'
def every_file_exists(*args, **kwargs):
return True
monkeypatch.setenv('DEBUG', '0')
monkeypatch.setattr(deck_chores.config, 'exists', every_file_exists)
monkeypatch.setattr(
docker.client.APIClient, '_retrieve_server_version', docker_api_version
)
generate_config()
result = cfg.__dict__.copy()
assert isinstance(result.pop('client'), docker.client.DockerClient)
assert result == {
'assert_hostname': False,
'client_timeout': DEFAULT_TIMEOUT_SECONDS,
'docker_host': 'unix://var/run/docker.sock',
'debug': False,
'default_max': 1,
'default_flags': ('image', 'service'),
'job_executor_pool_size': 10,
'label_ns': 'deck-chores.',
'logformat': '{asctime}|{levelname:8}|{message}',
'service_identifiers': (
'com.docker.compose.project',
'com.docker.compose.service',
),
'ssl_version': ssl.PROTOCOL_TLS,
'timezone': 'UTC',
}