spec icon indicating copy to clipboard operation
spec copied to clipboard

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

Open ontoneio opened this issue 2 years ago • 3 comments

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. Environment and pre-defined variables 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 in the mount property array like so:

"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:

[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 with in the mount property. Unless I am missing something in the docs.

Thanks

ontoneio avatar Jul 27 '23 21:07 ontoneio

If you take a look at the pre-defined variables table it calls out that containerEnv is only usable as an expansion source in the remoteEnv option...although the table header leaves a bit to be desired (just says "Type").

I'm not sure why that's the case exactly (I don't work on the reference CLI, which is what informed the spec)

avidal avatar Nov 28 '23 22:11 avidal

@avidal what you suggest (if I get the idea correctly) does not work either. Having this .devcontainer file:

"remoteEnv": {
  "HOME": "/home/vscode"
},
"workspaceMount": "source=${localWorkspaceFolder}/,target=${containerEnv:HOME},type=bind,consistency=cached",

I still get the following error:

[2023-12-10T19:25:05.698Z] Start: Run: /opt/homebrew/bin/podman run --sig-proxy=false -a STDOUT -a STDERR --mount source=/Users/filip.komarzyniec/my_folder/,target=${containerEnv:HOME},type=bind,consistency=cached --mount type=volume,src=vscode,dst=/vscode -l devcontainer.local_folder=/Users/filip.komarzyniec/my_folder -l devcontainer.config_file=/Users/filip.komarzyniec/my_folder/.devcontainer/devcontainer.json --userns=keep-id --entrypoint /bin/sh vsc-my-folder-ff86802263add83c79a982bce4a09566e6d62985ede81565f4faed5769c5352a -c echo Container started
[2023-12-10T19:25:05.837Z] Error: invalid container path "${containerEnv:HOME}", must be an absolute path

Is there any progress on the issue or any decisions on it whatsoever?

filip-komarzyniec avatar Dec 10 '23 19:12 filip-komarzyniec

Just bumped against this (exact same use case, too) in microsoft/vscode-remote-release#10003. Mounting volumes into the container user's home directory is useful for tools persisting configuration there.

stewartadam avatar Jun 24 '24 23:06 stewartadam