admin管理员组

文章数量:1122832

I am creating a dev container via devcontainer.json on a Windows 10 Host. Ubuntu 24.04 is my distro of choice and we have cloned the repo to WSL for performance gains.

On our Windows machines our developers created the necessary user level .npmrc files to connect to a private Azure Artifacts feed. I would like to avoid having folks recreate these .npmrc files in their dev containers so I am attempting to mount them like so:

// devcontainer.json
"image": "org/experience-builder:1.13-alpine",
"mounts": [
  {
    "source": "/mnt/c/Users/MY_WINDOWS_USERNAME/.npmrc",
    "target": "/root/.npmrc",
    "type": "bind"
  }
],

If we hard code MY_WINDOWS_USERNAME to our actual Windows user names this works. However, I would like to set this dynamically so we don't have to modify the devcontainer.json for each user.

I've tried setting an environment variable in initializeCommand as shown below but the variable appears to be blank when attempting to reference it the mounts configuration, causing the container to fail upon startup.

"initializeCommand": "export WINUSERPROFILE=$(wslpath $(pwsh.exe -nop -c '$env:USERPROFILE'))"

It's likely this is occurring because the variable is only available for the duration of the shell command. Once initializeCommand exits the variable is no longer available.

How can I set a dynamic mount source such that us developers can simply clone the repo and open the folder in vscode without any local file modification?

本文标签: dockerSetting devcontainerjson mount source based on user39s windows profile pathStack Overflow