images_manager¶
PodmanResource 管理器子类,用于图像。
- class ImagesManager(client: APIClient | None = None, podman_client: PodmanClient | None = None)[source]¶
基类:
BuildMixin
,Manager
用于图像资源的专用管理器。
初始化 Manager() 对象。
- 参数:
client – 配置为连接到 Podman 服务的 APIClient()。
podman_client – 配置为连接到 Podman 对象的 PodmanClient()。
- build(**kwargs) tuple[Image, Iterator[bytes]] ¶
返回构建的图像。
- 关键字参数:
path (str)
Dockerfile. (fileobj – 用作 Dockerfile 的文件对象。)
tag (str)
quiet (bool)
nocache (bool)
rm (bool)
timeout (int)
custom_context (bool)
encoding (str) – 流的编码。设置为 gzip 用于压缩(忽略)。)
pull (bool)
forcerm (bool)
dockerfile (str)
buildargs (Mapping[str,str)
container_limits (dict[str, Union[int,str]]) –
- 应用于构建过程创建的每个容器的限制字典。
有效键
memory (int): 设置构建的内存限制
memswap (int): 总内存(内存 + 交换),-1 表示禁用交换
cpushares (int): CPU 份额(相对权重)
cpusetcpus (str): 允许执行的 CPU,例如“0-3”,“0,1”
cpuperiod (int): CPU CFS (Completely Fair Scheduler) 周期(仅限 Podman)
cpuquota (int): CPU CFS (Completely Fair Scheduler) 配额(仅限 Podman)
shmsize (int) – 如果省略,系统使用 64MB
labels (Mapping[str,str])
cache_from (list[str])
target (str)
network_mode (str)
squash (bool)
extra_hosts (dict[str,str]) – 容器,作为主机名到 IP 地址的映射。
platform (str)
isolation (str) – 构建期间使用的隔离技术。(忽略))
use_config_proxy (bool) –(忽略))
http_proxy (bool) - 将 http 代理环境变量注入容器(仅限 Podman))
layers (bool)
output (str)
outputformat (str)
- 返回:
第一个项是构建的 podman.domain.images.Image
第二个项是构建日志
- 抛出:
BuildError – 构建期间发生错误时
APIError – 服务返回错误时
TypeError – 未指定路径或文件对象时
- get(name: str) Image [source]¶
按名称或 ID 返回图像。
- 参数:
name – 要搜索的图像 ID 或名称
- 抛出:
ImageNotFound – 图像不存在时
APIError – 服务返回错误时
- get_registry_data(name: str, auth_config=collections.abc.Mapping[str, str]) RegistryData [source]¶
返回图像的注册表数据。
提供以实现兼容性
- 参数:
name – 图像名称
auth_config – 覆盖已配置的凭据。需要用户名和密码键。
- 抛出:
APIError – 服务返回错误时
- list(**kwargs) list[Image] [source]¶
报告图像。
- 关键字参数:
name (str)
all (bool)
filters (Mapping[str, Union[str, list[str]]) –
可用过滤器
dangling (bool)
label (Union[str, list[str]]): 格式为“key”或“key=value”
- 抛出:
APIError – 服务返回错误时
- load(data: bytes | None = None, file_path: PathLike | None = None) Generator[Image, None, None] [source]¶
恢复以前保存的图像。
- 参数:
data – 以 tarball 格式加载的图像。
file_path – Tarball 的路径。适用于 str 和 Path-like 对象
- 抛出:
APIError – 服务返回错误时。
PodmanError – 参数设置不正确时。
- prepare_model(attrs: PodmanResource | Mapping[str, Any]) PodmanResourceType ¶
从一组属性创建模型。
- prune(all: bool | None = False, external: bool | None = False, filters: Mapping[str, Any] | None = None) dict[Literal['ImagesDeleted', 'SpaceReclaimed'], Any] [source]¶
删除未使用的图像。
Untagged 键将始终为“”。
- 参数:
all – 删除所有未被容器使用的图像,而不仅仅是悬空图像。
external – 即使图像被外部容器使用也删除它们
(e.g
containers). (通过构建)
filters –
限定要修剪的图像。可用过滤器
dangling (bool): 当为 true 时,仅删除未使用和未标记的图像。
- label: (dict): 按标签筛选。
示例:filters={“label”: {“key”: “value”}} filters={“label!”: {“key”: “value”}}
until (str): 删除早于此时间戳的图像。
- 抛出:
APIError – 服务返回错误时
- prune_builds() dict[Literal['CachesDeleted', 'SpaceReclaimed'], Any] [source]¶
删除构建器缓存。
- 为完成 API 而包含的方法,该操作始终返回空的
CacheDeleted 和零 SpaceReclaimed。
- pull(repository: str, tag: str | None = None, all_tags: bool = False, **kwargs) Image | list[Image] | Iterator[str] [source]¶
请求 Podman 服务从仓库拉取图像。
- 参数:
repository – 要拉取的仓库
tag – 要拉取的图像标签。默认值:“latest”。
all_tags – 从仓库拉取所有图像标签。
- 关键字参数:
auth_config (Mapping[str, str]) – 此请求的配置。auth_config 应包含 username 和 password 键才有效。
compatMode (bool) – 默认值:True。
decode (bool) – 仅适用于
stream=True
platform (str)
policy (str) - 拉取策略。“always”(默认))
progress_bar (bool) – 兼容性端点)。默认值:False
tls_verify (bool) – True。
stream (bool) – 默认值:False。
- 返回:
当 stream 为 True 时,返回一个生成器,发布服务拉取进度。如果 all_tags 为 True,则返回拉取的 Image 列表而不是单个 Image。
- 抛出:
APIError – 服务返回错误时
- push(repository: str, tag: str | None = None, **kwargs) str | Iterator[str | dict[str, Any]] [source]¶
将图像或仓库推送到注册表。
- 参数:
repository – 推送的目标仓库
tag – 如果给定,则推送的标签
- 关键字参数:
str] (auth_config (Mapping[str,) – 覆盖已配置的凭据。必须包含 username 和 password 键。
decode (bool) – 将服务器返回的数据作为 dict[str, Any] 返回。除非 stream=True,否则忽略。
destination (str) – 图像的备用目标。(仅限 Podman)
stream (bool) – 将输出作为阻塞生成器返回。默认值:False。
tlsVerify (bool) – 要求 TLS 验证。
format (str) – 推送图像时使用的清单类型(oci、v2s1 或 v2s2)。默认是源的清单类型,带回退。
- 抛出:
APIError – 服务返回错误时
- remove(image: Image | str, force: bool | None = None, noprune: bool = False) list[dict[Literal['Deleted', 'Untagged', 'Errors', 'ExitCode'], str | int]] [source]¶
从 Podman 服务删除图像。
- 参数:
image – 要删除的图像名称或 ID
force – 即使图像正在使用也删除它
noprune – 忽略。
- 抛出:
ImageNotFound – 图像不存在时
APIError – 服务返回错误时
- scp(source: str, dest: str | None = None, quiet: bool | None = False) str [source]¶
在主机之间安全地复制图像。
- 参数:
source – 源连接/图像
dest – 目标连接/图像
quiet – 不打印保存/加载输出,仅打印图像
- 返回:
包含加载图像的字符串
- 抛出:
APIError – 服务返回错误时
- search(term: str, **kwargs) list[dict[str, Any]] [source]¶
在注册表上搜索图像。
- 参数:
term – 用于定位图像结果。
- 关键字参数:
filters (Mapping[str, list[str]) –
优化搜索结果。可用过滤器
is-automated (bool): 图像构建是自动的。
is-official (bool): 图像构建由产品提供商拥有。
stars (int): 图像至少有此数量的星级。
noTrunc (bool) – 不截断任何结果字符串。默认值:True。
limit (int) – 最大结果数。
listTags (bool) – 列出仓库中可用的标签。默认值:False
- 抛出:
APIError – 服务返回错误时
- property resource¶
prepare_model() 将创建 Image 类。
- 类型: