Skip to content

Proposal: enable optional bind mounts #132

Description

When specifying mounts in devcontainer.json, we can use volume or bind mounts:

 "mounts": [
    // Keep command history
    {"type":"volume", "source": "my-bash-history", "target":"/home/vscode/commandhistory"},
    // Mounts the login details from the host machine to azcli works in the container
    {"type": "bind", "source": "${env:HOME}${env:USERPROFILE}/.azure", "target":"/home/vscode/.azure"},
    // Mount docker socket for docker builds
    {"type": "bind", "source": "/var/run/docker.sock", "target": "/var/run/docker.sock"}
  ],

By default, if the src doesn't exist on the host the dev container start fails. In some scenarios it is desirable to create a mount if it exists, but it is preferable to continue without the mount rather than fail to start.

An example is when you wish to mount the .azure folder from the host into the dev container to share login credentials between host and container as a convenience mechanism. In this scenario, it would be nice to make the mount optional, i.e. to strip the mount out of the configuration if the src doesn't exist on the host. In this example, this would be if the user doesn't have the azure CLI installed on the host. If the mount was optional, the dev container would still run and the user would log in inside the dev container.

With this extra property to items in the mounts array to allow bind mounts to be indicated as optional, the above bind mount for the .azure folder would look like:

 "mounts": [
    // Mounts the login details from the host machine to azcli works in the container
    {"type": "bind", "source": "${env:HOME}${env:USERPROFILE}/.azure", "target":"/home/vscode/.azure", "optional": true},
  ],

This could also be supported by the string form:

 "mounts": [
    // Mounts the login details from the host machine to azcli works in the container
    "type=bind,source=${env:HOME}${env:USERPROFILE}/.azure,target=/home/vscode/.azure,optional=true",
  ],

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalStill under discussion, collecting feedback

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions