Docker runner

警告

此功能是实验性的,可能会发生重大更改。有关更多信息,请参阅 Conan 稳定性 部分。

如何使用 Docker runner

要在 Docker 容器内运行 Conan,必须在宿主配置文件中定义一个 [runner] 部分,其中包含以下字段

  • type (必选): 指定要使用的 runner,在本例中为 docker

  • dockerfile (可选,默认: None): Dockerfile 的绝对路径,如果需要构建 Docker 镜像。

  • image (可选,默认: conan-runner-default): 要从 registry 下载的 Docker 镜像名称,或者如果提供了 Dockerfile 路径,则为本地构建的镜像名称。

  • cache (可选,默认: clean): 确定 Docker 容器如何与宿主的 Conan 缓存交互。

    • clean: 使用一个空的缓存。

    • copy: 使用 conan cache save/restore 命令将宿主缓存复制到容器中。

    • shared: 将宿主的 Conan 缓存挂载为共享卷。

  • remove (可选,默认: false): 指定在执行 Conan 命令后是否删除容器 (true 或 false)。

  • configfile (可选,默认: None): 包含附加参数的配置文件绝对路径(有关详细信息,请参阅 额外配置 部分)。

  • build_context (可选,默认: None): 定义 Docker 构建上下文(有关详细信息,请参阅 额外配置 部分)。

  • platform (可选,默认: None): 指定构建容器的平台(例如 linux/amd64)。这对于 Mac Silicon 用户尤其有用。

注意

  • 根据容器内外的用户,shared 缓存选项可能会导致权限问题。 建议使用 copy 缓存以获得更高的稳定性,尽管设置时间会略微增加。

  • runner 配置文件部分不会影响包 ID。

额外配置

为了更精细地控制容器的构建和执行,可以在 configfile YAML 文件中定义额外的参数。

image: image_name # The image to build or run.
build:
    dockerfile: /dockerfile/path # Dockerfile path.
    build_context: /build/context/path # Path within the build context to the Dockerfile.
    build_args: # A dictionary of build arguments
        foo: bar
    cacheFrom: # A list of images used for build cache resolution
        - image_1
run:
    name: container_name # The name for this container.
    containerEnv: # Environment variables to set inside the container.
        env_var_1: env_value
    containerUser: user_name # Username or UID to run commands as inside the container.
    privileged: False # Run as privileged
    capAdd: # Add kernel capabilities.
        - SYS_ADMIN
        - MKNOD
    securityOpt: # A list of string values to customize labels for MLS systems, such as SELinux.
        - opt_1
    mounts: # A dictionary to configure volumes mounted inside the container.
        /home/user1/: # The host path or a volume name
            bind: /mnt/vol2 # The path to mount the volume inside the container
            mode: rw # rw to mount the volume read/write, or ro to mount it read-only.
    network: my-network # Specifies the network for the container.

如何在 runner 中运行 conan create

注意

docker runner 功能仅受 conan create 命令支持。 conan install --build 命令不受支持。

以下链接提供了如何使用 Conan Docker runner 的示例