devcontainers / devcontainers/spec

Proposal: enable optional bind mounts

Open
#132 17 comments 59 reactions 0 assignees View on GitHub
proposal
Dominant language
No language data
Stars
5.7k
Forks
496
PR merge metrics
No merged PRs in 30d

Description

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

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

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

```jsonc
"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",
],
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.