devcontainers / devcontainers/cli
Incorrect field used as mapping key for deserialization of 'mounts' in devcontainer.json
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 457
- Avg merge
- 13h 17m
- Merged PRs (30d)
- 6
Description
If specifying mounts in `devcontainer.json` and trying to mount the same volume in different locations, you get a deserialization error.
```
[2024-05-08T20:39:45.846Z] parsing /tmp/devcontainercli-root/docker-compose/docker-compose.devcontainer.containerFeatures-1715200785780-516d96c0-3c67-479f-b191-c3c3d323c3c3.yml: yaml: unmarshal errors:
line 28: mapping key "build-obj" already defined at line 26
```
However this works without problems if you specify the volumes in `docker-compose.yml`.
```
volumes:
- build-obj:/workspace/src/a/build
- build-obj:/workspace/src/b/build
```
If a unique key is needed, the _target_ and not the source of the mount should be used.
Log fragment
```
[2024-05-08T20:39:45.780Z] Docker Compose override file for creating container:
version: '3.8'
services:
'dev-build':
entrypoint: ["/bin/sh", "-c", "echo Container started\n
trap \"exit 0\" 15\n
\n
exec \"$$@\"\n
while sleep 1 & wait $$!; do :; done", "-"]
command: ["/usr/bin/sleep","infinity"]
labels:
- 'devcontainer.local_folder=/root/workspace/dev-container'
- 'devcontainer.config_file=/root/workspace/dev-container/.devcontainer/devcontainer.json'
volumes:
- /root/workspace/dev-container:/workspace
- build-obj:/workspace/src/a/build
- build-obj:/workspace/src/b/build
- vscode:/vscode
volumes:
build-obj:
build-obj:
vscode:
external: true
[2024-05-08T20:39:45.780Z] Writing docker-compose.devcontainer.containerFeatures-1715200785780-516d96c0-3c67-479f-b191-c3c3d323c3c3.yml to /tmp/devcontainercli-root/docker-compose
[2024-05-08T20:39:45.781Z] Start: Run: /usr/bin/docker-compose --project-name devcontainer -f /root/workspace/dev-container/.devcontainer/docker-compose.yml -f /tmp/devcontainercli-root/docker-compose/docker-compose.devcontainer.build-1715200784920.yml -f /tmp/devcontainercli-root/docker-compose/docker-compose.devcontainer.containerFeatures-1715200785780-516d96c0-3c67-479f-b191-c3c3d323c3c3.yml up -d
[2024-05-08T20:39:45.846Z] parsing /tmp/devcontainercli-root/docker-compose/docker-compose.devcontainer.containerFeatures-1715200785780-516d96c0-3c67-479f-b191-c3c3d323c3c3.yml: yaml: unmarshal errors:
line 28: mapping key "build-obj" already defined at line 26
```
Contributor guide
Assessment
This issue has not been assessed yet.