我在 Windows 11 上通过 Docker Desktop 运行 Docker v25.0.3。我无法让我的绑定挂载卷与 Docker Compose 一起使用。
我的
docker-compose.yaml
看起来像这样:
version: '3'
services:
oidc-server-mock:
container_name: oidc-server-mock
image: ghcr.io/soluto/oidc-server-mock:latest
ports:
- '8080:80'
environment:
ASPNETCORE_ENVIRONMENT: Development
CLIENTS_CONFIGURATION_PATH: config/clients-config.json
volumes:
- type: bind
- source: /mnt/c/Users/my/local/config/path
- target: /config
如果我不使用 docker compose
,而是使用带有以下参数的 Powershell 中的 docker run
,那么它
确实可以工作:
--mount type=bind,source=C:\my\local\config\path,target=/config
但由于某种原因
docker compose
不喜欢我的文件。
我尝试过的:我尝试了在线搜索我的
docker-compose.yml
的 -source
参数所建议的每种可以想象到的不同路径格式,路径周围有双引号和没有双引号。此外,我在网上找不到任何逐字提及此特定错误消息“缺少安装目标”的内容。
您的语法不正确:
volumes:
- type: bind
- source: /mnt/c/Users/my/local/config/path
- target: /config
这应该是:
volumes:
- type: bind
source: /mnt/c/Users/my/local/config/path
target: /config
-
表示列表元素。您对当前配置的基本操作是定义 3 个不同的卷:一个仅包含 type
,另一个仅包含 source
,第三个仅包含 target
。该错误涉及列表中的第一个 ([0]
) 元素。
如果您要添加第二卷,语法将是:
volumes:
- type: bind
source: /mnt/c/Users/my/local/config/path
target: /config
- type: bind
source: /foo
target: /bar