Docker runner¶
警告
此功能是实验性的,可能会发生重大更改。有关更多信息,请参阅 Conan 稳定性 部分。
如何使用 Docker runner¶
要在 Docker 容器中运行 Conan,必须在宿主机的 profile 中定义一个 [runner] 部分,并包含以下字段:
type(必填):指定要使用的 runner,在这种情况下是docker。dockerfile(可选,默认: None):Dockerfile 的绝对路径,如果需要构建 Docker 镜像。image(可选,默认: conan-runner-default):要从注册表中下载的 Docker 镜像名称,或者在提供了 Dockerfile 路径时本地构建的镜像名称。cache(可选,默认: clean):确定 Docker 容器如何与宿主机的 Conan 缓存进行交互。clean:使用一个空的缓存。copy:使用 conan cache save/restore 命令将宿主机缓存复制到容器中。shared:将宿主机的 Conan 缓存挂载为一个共享卷。
remove(可选,默认: false):指定执行 Conan 命令后是否删除容器(true 或 false)。configfile(可选,默认: None):一个包含附加参数的配置文件(YAML 格式)的绝对路径(有关详细信息,请参阅 **附加配置** 部分)。build_context(可选,默认: None):定义 Docker 构建上下文(有关详细信息,请参阅 **附加配置** 部分)。platform(可选,默认: None):指定构建容器的平台(例如,linux/amd64)。这对于 Mac Silicon 用户尤其有用。
注意
根据容器内外用户的不同,
shared缓存选项可能会导致权限问题。建议使用copy缓存以获得更高的稳定性,尽管初始设置时间会略有增加。Runner profile 部分不影响包 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 的示例: