当前位置: 首页>>代码示例>>Python>>正文


Python Client.get_image方法代码示例

本文整理汇总了Python中docker.client.Client.get_image方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_image方法的具体用法?Python Client.get_image怎么用?Python Client.get_image使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docker.client.Client的用法示例。


在下文中一共展示了Client.get_image方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_docker_image

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import get_image [as 别名]
def download_docker_image(docker_image, target_file, cache=None):
	try:
		from docker.client import Client
		from docker.utils import kwargs_from_env
		kwargs = kwargs_from_env()
		kwargs['tls'].assert_hostname = False
		docker_cli = Client(**kwargs)
		image = docker_cli.get_image(docker_image)
		image_tar = open(target_file,'w')
		image_tar.write(image.data)
		image_tar.close()
	except Exception as e:
		if cache is not None:
			cached_file = os.path.join(cache, docker_image.lower().replace('/','-').replace(':','-') + '.tgz')
			if os.path.isfile(cached_file):
				print 'using cached version of', docker_image
				urllib.urlretrieve(cached_file, target_file)
				return
			print >> sys.stderr, docker_image, 'not found in cache', cache
			sys.exit(1)
		if isinstance(e, KeyError):
			print >> sys.stderr, 'docker not configured on this machine (or environment variables are not properly set)'
		else:
			print >> sys.stderr, docker_image, 'not found on local machine'
			print >> sys.stderr, 'you must either pull the image, or download it and use the --docker-cache option'
		sys.exit(1)
开发者ID:pombredanne,项目名称:tile-generator,代码行数:28,代码来源:build.py

示例2: download_docker_image

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import get_image [as 别名]
def download_docker_image(docker_image, target_file):
	from docker.client import Client
	from docker.utils import kwargs_from_env
	kwargs = kwargs_from_env()
	kwargs['tls'].assert_hostname = False
	docker_cli = Client(**kwargs)
	image = docker_cli.get_image(docker_image)
	image_tar = open(target_file,'w')
	image_tar.write(image.data)
	image_tar.close()
开发者ID:frodenas,项目名称:tile-generator,代码行数:12,代码来源:build.py

示例3: download_docker_image

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import get_image [as 别名]
def download_docker_image(docker_image, target_file):
	from docker.client import Client
	try: # First attempt boot2docker, because it is fail-fast
		from docker.utils import kwargs_from_env
		kwargs = kwargs_from_env()
		kwargs['tls'].assert_hostname = False
		docker_cli = Client(**kwargs)
	except KeyError as e: # Assume this means we are not using boot2docker
		docker_cli = Client(base_url='unix://var/run/docker.sock', tls=False)
	image = docker_cli.get_image(docker_image)
	image_tar = open(target_file,'w')
	image_tar.write(image.data)
	image_tar.close()
开发者ID:Dwaligon,项目名称:tile-generator,代码行数:15,代码来源:build.py

示例4: download

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import get_image [as 别名]
def download(url, filename, cache=None):
	if cache is not None:
		basename = os.path.basename(filename)
		cachename = os.path.join(cache, basename)
	 	if os.path.isfile(cachename):
			print('- using cached version of', basename)
			shutil.copy(cachename, filename)
			return
	if url.startswith("http:") or url.startswith("https"):
		# [mboldt:20160908] Using urllib.urlretrieve gave an "Access
		# Denied" page when trying to download docker boshrelease.
		# I don't know why. requests.get works. Do what works.
		response = requests.get(url, stream=True)
		response.raise_for_status()
		with open(filename, 'wb') as file:
			for chunk in response.iter_content(chunk_size=1024):
				if chunk:
					file.write(chunk)
	elif url.startswith("docker:"):
		docker_image = url.lstrip("docker:").lstrip("/").lstrip("/")
		try:
			from docker.client import Client
			from docker.utils import kwargs_from_env
			kwargs = kwargs_from_env()
			kwargs['tls'] = False
			docker_cli = Client(**kwargs)
			image = docker_cli.get_image(docker_image)
			image_tar = open(filename,'w')
			image_tar.write(image.data)
			image_tar.close()
		except KeyError as e:
			print('docker not configured on this machine (or environment variables are not properly set)', file=sys.stderr)
			sys.exit(1)
		except:
			print(docker_image, 'not found on local machine', file=sys.stderr)
			print('you must either pull the image, or download it and use the --cache option', file=sys.stderr)
			sys.exit(1)
	else:
		shutil.copy(url, filename)
开发者ID:chrisjs,项目名称:tile-generator,代码行数:41,代码来源:util.py

示例5: download

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import get_image [as 别名]
def download(url, filename, cache=None):
	if cache is not None:
		basename = os.path.basename(filename)
		cachename = os.path.join(cache, basename)
	 	if os.path.isfile(cachename):
			print('- using cached version of', basename)
			shutil.copy(cachename, filename)
			return
	# Special url to find a file associated with a github release.
	# github://cf-platform-eng/meta-buildpack/meta-buildpack.tgz
	# will find the file named meta-buildpack-0.0.3.tgz in the latest
	# release for https://github.com/cf-platform-eng/meta-buildpack
	if url.startswith("github:"):
		repo_name = url.lstrip("github:").lstrip("/").lstrip("/")
		file_name = os.path.basename(repo_name)
		repo_name = os.path.dirname(repo_name)
		url = "https://api.github.com/repos/" + repo_name + "/releases/latest"
		response = requests.get(url, stream=True)
		response.raise_for_status()
		release = response.json()
		assets = release.get('assets', [])
		url = None
		pattern = re.compile('.*\\.'.join(file_name.rsplit('.', 1))+'\\Z')
		for asset in assets:
			if pattern.match(asset['name']) is not None:
				url = asset['browser_download_url']
				break
		if url is None:
			print('no matching asset found for repo', repo_name, 'file', file_name, file=sys.stderr)
			sys.exit(1)
		# Fallthrough intentional, we now proceed to download the URL we found
	if url.startswith("http:") or url.startswith("https"):
		# [mboldt:20160908] Using urllib.urlretrieve gave an "Access
		# Denied" page when trying to download docker boshrelease.
		# I don't know why. requests.get works. Do what works.
		response = requests.get(url, stream=True)
		response.raise_for_status()
		with open(filename, 'wb') as file:
			for chunk in response.iter_content(chunk_size=1024):
				if chunk:
					file.write(chunk)
	elif url.startswith("docker:"):
		docker_image = url.lstrip("docker:").lstrip("/").lstrip("/")
		try:
			from docker.client import Client
			from docker.utils import kwargs_from_env
			kwargs = kwargs_from_env()
			kwargs['tls'] = False
			docker_cli = Client(**kwargs)
			image = docker_cli.get_image(docker_image)
			image_tar = open(filename,'w')
			image_tar.write(image.data)
			image_tar.close()
		except KeyError as e:
			print('docker not configured on this machine (or environment variables are not properly set)', file=sys.stderr)
			sys.exit(1)
		except:
			print(docker_image, 'not found on local machine', file=sys.stderr)
			print('you must either pull the image, or download it and use the --cache option', file=sys.stderr)
			sys.exit(1)
	elif os.path.isdir(url):
		shutil.copytree(url, filename)
	else:
		shutil.copy(url, filename)
开发者ID:cf-platform-eng,项目名称:tile-generator,代码行数:66,代码来源:util.py


注:本文中的docker.client.Client.get_image方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。