6

I am using VSCode devcontainers, how do you have a mount section in the devcontainers.json with that is compatible for both windows and MAC? I have a problem accessing the source=... section under the "mounts" section.

// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.106.0/containers/python-3
{
    "name": "Python 3",
    "context": "..",
    "dockerFile": "Dockerfile",

    // Set *default* container specific settings.json values on container create.
    "settings": {
        "terminal.integrated.shell.linux": "/bin/bash",
        "python.pythonPath": "/usr/local/bin/python",
        "python.linting.enabled": true,
        "python.linting.pylintEnabled": true,
        "python.linting.pylintPath": "venv/bin/pylint",
    },

    // Change <username> to user path (Ex. /Users/vfrank/ on a MAC)
    "mounts": [
        "source=<full home path>/.aws/credentials,target=/home/vscode/.aws/credentials,type=bind,consistency=cached"
    ],
    
    // Add the IDs of extensions you want installed when the container is created.
    "extensions": [
        "ms-python.python"
    ],

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    "postCreateCommand": "echo 'done'",

    // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode"
}

Works on MAC but not on Windows

    "mounts": [
        "source=${localEnv:HOME}${localEnv:USERPROFILE}/.aws/credentials,target=/home/vscode/.aws/credentials,type=bind,consistency=cached"
    ]

Works on windows but not on MAC

    "mounts": [
        "source=~/.aws/credentials,target=/home/vscode/.aws/credentials,type=bind,consistency=cached"
    ]

I have docker file sharing setup for C drive on Windows and /Users on MAC, but the error I am getting when using devcontainers is that the folder or file does not exist. I can make it work on both computers so it is not related to file permissions or access from docker.

I am looking for a single source=... command that works on both Windows (10+) and MAC.

vfrank66
  • 1,318
  • 19
  • 28
  • your example for Win doesn't work for me. But I make it work like this "source=${localEnv:USERPROFILE}\\.aws\\credentials,target=/root/.aws/credentials,type=bind,consistency=cached" – dannikoti May 18 '21 at 12:23

1 Answers1

0

If you do this:

"source=${localEnv:HOME}${localEnv:USERPROFILE}\\.aws\\credentials,target=/root/.aws/credentials,type=bind,consistency=cached"

Then only one expansion will be non-empty on each platform and you will get the result you want.

Andrew
  • 2,943
  • 18
  • 23