images_build

镜像构建支持的 Mixin。

class BuildMixin[源]

基类:object

为 ImagesManager 提供构建方法的类。

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(完全公平调度器)周期(仅限 Podman)

    • cpuquota (int):CPU CFS(完全公平调度器)配额(仅限 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 – 当 path 和 fileobj 都未指定时