Docker 运行器¶
警告
此功能为实验性功能,可能会有破坏性更改。有关更多信息,请参阅 Conan 稳定性 部分。
如何使用 Docker 运行器¶
要在 Docker 容器内运行 Conan,您需要在主机配置文件中定义一个 [runner]
部分,并使用以下字段
type
(必需): 定义我们要使用的运行器类型,在本例中为docker
。dockerfile
(可选,默认为 None): Dockerfile 的绝对路径,如果您想构建 Docker 镜像。image
(可选,默认为 conan-runner-default): 您要从 Docker 注册表下载的 Docker 镜像名称,或者在您定义 Dockerfile 路径的情况下,构建的镜像名称。cache
(可选,默认为 clean): Docker 容器如何(或不)使用主机的 Conan 缓存。clean
: 使用空缓存。copy
: 使用 conan cache save/restore 命令将主机缓存复制到容器内。shared
: 将主机的 Conan 缓存挂载为共享卷。
remove
(可选,默认为 false):true
或false
。在运行 Conan 命令后移除容器。configfile
(可选,默认为 None): 包含额外参数的配置文件的绝对路径(有关更多信息,请参阅额外配置部分)。
注意
您只能使用位于 conan profiles 文件夹内的配置文件。
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
mount: # 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 运行器的示例