devcontainers / devcontainers/spec

BUG: Predefined variables only partially work in `mounts` section

Open
#282 3 comments 4 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
5.7k
Forks
496
PR merge metrics
No merged PRs in 30d

Description

In the `mounts` property documentation it reads:

> Defaults to unset. Cross-orchestrator way to add additional mounts to a container. Each value is a string that accepts the same values as the [Docker CLI --mount flag](https://docs.docker.com/engine/reference/commandline/run/#mount). Environment and [pre-defined variables](https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson) may be referenced in the value. For example:
"mounts": [{ "source": "dind-var-lib-docker", "target": "/var/lib/docker", "type": "volume" }]

When trying to use [pre-defined variables](https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson) in the `mount` property array like so:

```json
"mounts": [
"source=${localEnv:HOME}/.bashrc,target=${containerEnv:HOME}/.bashrc,type=bind"
],
```

Seems like the `${localEnv:HOME}` variable is working but not the `containerEnv`. I am met with this error:

```bash
[2023-07-27T21:29:17.441Z] Start: Run: docker run --sig-proxy=false -a STDOUT -a STDERR --mount source=/home/vscode/.bashrc,target=${containerEnv:HOME}/.bashrc,type=bind --mount type=volume,src=vscode,dst=/vscode --mount type=bind,src=/mnt/wslg/runtime-dir/wayland-0,dst=/tmp/vscode-wayland-f5cf98e1-b777-482d-a8b0-901e9ce6936c.sock -l devcontainer.local_folder=\\wsl.localhost\Ubuntu\home\vscode\projects\web-cms -l devcontainer.config_file=/home/vscode/projects/web-cms/.devcontainer/devcontainer.json -e GITHUB_ACTIONS= -e GLOBAL_DEPS=/workspaces/node_modules/.bin -e WSLENV=VSCODE_CLI_REMOTE_ENV/w:ELECTRON_RUN_AS_NODE/w:WT_SESSION:VSCODE_BIN/p:GIT_CRED_MGR/p:DOCKER_LOCAL_BIN:WT_PROFILE_ID --init --privileged --privileged --entrypoint /bin/sh vsc-web-cms-91be336f19f43f7d6233276339f0cc37087480b85a7d91e2890c5b9dfef4ecdb-uid -c echo Container started
[2023-07-27T21:29:17.515Z] docker: Error response from daemon: invalid mount config for type "bind": invalid mount path: '${containerEnv:HOME}/.bashrc' mount path must be absolute.
See 'docker run --help'.
```

So it seems like you cannot actually use [pre-defined variables](https://containers.dev/implementors/json_reference/#variables-in-devcontainerjson) with in the `mount` property. Unless I am missing something in the docs.

Thanks

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.