Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount path based on env var #1132

Open
devhl-labs opened this issue Sep 27, 2024 · 2 comments
Open

Mount path based on env var #1132

devhl-labs opened this issue Sep 27, 2024 · 2 comments

Comments

@devhl-labs
Copy link

I am trying to mount ~/.azure into my devcontainer. The issue is that this directory is a symlink to my Windows path. I can get the mount to work if I mount both paths, the problem is that I don't want to commit my Windows path into git because it wont be the same for others. For others, it may not even be a symlink. Is it possible to mount my symlink using an environment variable if the user has it set?

@samruddhikhandale
Copy link
Member

Yes, you can use an environment variable in your devcontainer.json to mount the symlink. Define the variable in an .env file and reference it in the mounts section.

eg.

{
    "name": "My Dev Container",
    "image": "mcr.microsoft.com/vscode/devcontainers/base:0.202.6",
    "mounts": [
        "source=${AZURE_PATH},target=/root/.azure,type=bind,consistency=cached"
    ],
    "remoteEnv": {
        "AZURE_PATH": "${localEnv:AZURE_PATH}"
    }
}

@devhl-labs
Copy link
Author

This gives me an error Error response from daemon: ${AZURE_PATH} is not an absolute path.

    "mounts": [
        "type=bind,source=${localEnv:HOME}/.bash_history,target=${localEnv:HOME}/.bash_history",
        "type=bind,source=${localEnv:HOME}/.ssh,target=${localEnv:HOME}/.ssh,readonly",
        "type=bind,source=${localEnv:HOME}/.azure,target=${localEnv:HOME}/.azure",
        "source=${AZURE_PATH},target=/root/.azure,type=bind,consistency=cached"
    ],
    "runArgs": [
        "--env-file",
        ".devcontainer/devcontainer.env"
    ],
    "remoteEnv": {
        "AZURE_PATH": "${localEnv:AZURE_PATH}"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants