Docker 运行器¶
警告
此功能是实验性的,可能会发生重大更改。有关更多信息,请参阅 Conan 稳定性 部分。
如何使用 Docker 运行器¶
要在 Docker 容器中运行 Conan,必须在主机配置文件中定义一个 [runner]
部分,并包含以下字段
type
(强制):指定要使用的运行器,在此情况下为docker
。dockerfile
(可选,默认值:无):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
(可选,默认值:无):包含额外参数的配置文件的绝对路径(详情请参阅 额外配置 部分)。build_context
(可选,默认值:无):定义 Docker 构建上下文(详情请参阅 额外配置 部分)。platform
(可选,默认值:无):指定用于构建容器的平台(例如,linux/amd64
)。这对于 Mac Silicon 用户特别有用。
注意
shared
缓存选项可能会根据容器内部和外部的用户而导致权限问题。建议使用copy
缓存以获得更高的稳定性,尽管设置时间会略有增加。运行器配置文件部分不影响包 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.
如何在运行器中运行 conan create¶
注意
Docker 运行器功能仅支持 conan create
命令。conan install --build
命令不受支持。
以下链接提供了如何使用 Conan Docker 运行器的示例