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):包含附加参数的配置文件的绝对路径(详情请参见 extra configuration 部分)。build_context
(可选,默认:None):定义 Docker 构建上下文(详情请参见 extra configuration 部分)。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 的示例: