本文整理汇总了Python中docker.client.Client.version方法的典型用法代码示例。如果您正苦于以下问题:Python Client.version方法的具体用法?Python Client.version怎么用?Python Client.version使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docker.client.Client
的用法示例。
在下文中一共展示了Client.version方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_docker
# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import version [as 别名]
def _init_docker():
kwargs = kwargs_from_env()
if 'tls' in kwargs:
# see http://docker-py.readthedocs.org/en/latest/boot2docker/
import requests.packages.urllib3 as urllib3
urllib3.disable_warnings()
kwargs['tls'].assert_hostname = False
docker = Client(**kwargs)
try:
docker.version()
except:
raise UserMessageException("Please set up 'docker' correctly")
return docker
示例2: cli
# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import version [as 别名]
def cli(ctx, url, network):
# initialize Client
cl = Client(base_url=url, version='auto')
# output version to show the connected succeeded
v = cl.version()
info('Connected to Docker {v[Version]}, api version '
'{v[ApiVersion]}.'.format(v=v))
# find frontend network
nets = [n for n in cl.networks(names=[network]) if n['Name'] == network]
assert len(nets) < 2 # WTF?
if not nets:
exit_err("Could not find a network name {!r}".format(network))
ctx.obj = {'cl': cl, 'network_name': network, 'network': nets[0]['Name']}
示例3: get_docker_client
# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import version [as 别名]
def get_docker_client():
"""
Try to fire up boot2docker and set any environmental variables
"""
# For Mac
try:
# Get boot2docker info (will fail if not Mac)
process = ['boot2docker', 'info']
p = subprocess.Popen(process, stdout=PIPE)
boot2docker_info = json.loads(p.communicate()[0])
# Defaults
docker_host = ''
docker_cert_path = ''
docker_tls_verify = ''
# Start the boot2docker VM if it is not already running
if boot2docker_info['State'] != "running":
print('Starting Boot2Docker VM:')
# Start up the Docker VM
process = ['boot2docker', 'start']
subprocess.call(process)
if ('DOCKER_HOST' not in os.environ) or ('DOCKER_CERT_PATH' not in os.environ) or ('DOCKER_TLS_VERIFY' not in os.environ):
# Get environmental variable values
process = ['boot2docker', 'shellinit']
p = subprocess.Popen(process, stdout=PIPE)
boot2docker_envs = p.communicate()[0].split()
for env in boot2docker_envs:
if 'DOCKER_HOST' in env:
docker_host = env.split('=')[1]
elif 'DOCKER_CERT_PATH' in env:
docker_cert_path = env.split('=')[1]
elif 'DOCKER_TLS_VERIFY' in env:
docker_tls_verify = env.split('=')[1]
# Set environmental variables
os.environ['DOCKER_TLS_VERIFY'] = docker_tls_verify
os.environ['DOCKER_HOST'] = docker_host
os.environ['DOCKER_CERT_PATH'] = docker_cert_path
else:
# Handle case when boot2docker is already running
docker_host = os.environ['DOCKER_HOST'].split('=')[1]
# Get the arguments form the environment
client_kwargs = kwargs_from_env(assert_hostname=False)
client_kwargs['version'] = MINIMUM_API_VERSION
# Find the right version of the API by creating a DockerClient with the minimum working version
# Then test to see if the Docker is running a later version than the minimum
# See: https://github.com/docker/docker-py/issues/439
version_client = DockerClient(**client_kwargs)
client_kwargs['version'] = get_api_version(MAX_CLIENT_DOCKER_API_VERSION, version_client.version()['ApiVersion'])
# Create Real Docker client
docker_client = DockerClient(**client_kwargs)
# Derive the host address only from string formatted: "tcp://<host>:<port>"
docker_client.host = docker_host.split(':')[1].strip('//')
return docker_client
# For Linux
except OSError:
# Find the right version of the API by creating a DockerClient with the minimum working version
# Then test to see if the Docker is running a later version than the minimum
# See: https://github.com/docker/docker-py/issues/439
version_client = DockerClient(base_url='unix://var/run/docker.sock', version=MINIMUM_API_VERSION)
version = get_api_version(MAX_CLIENT_DOCKER_API_VERSION, version_client.version()['ApiVersion'])
docker_client = DockerClient(base_url='unix://var/run/docker.sock', version=version)
docker_client.host = DEFAULT_DOCKER_HOST
return docker_client
except:
raise
示例4: Client
# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import version [as 别名]
from docker.client import Client
from docker.utils import kwargs_from_env
cli = Client(**kwargs_from_env())
container = cli.create_container(image='busybox:latest', command='/bin/echo 2342', rm=True)
print(container)
response = cli.start(container=container.get('Id'))
print(container)
print(response)
print(container.logs())
print(cli.version())