如何将挂载绑定到 vscode devcontainer 而无需在 devcontainer.json 中对其进行硬编码
在 这个问题< /a> 建议提交.devcontainer.json
。
我同意,但有一个问题。我需要将本地目录绑定挂载到我的 devcontainer 中。这需要我的同事没有的本地路径。目的是将我的 GCP 凭证挂载到我的 devcontainer 中,以便与 gcloud CLI 一起使用。
我的 .devcontainer.json 看起来像:
{
"image": "some/image",
// ... settings, extensions, forwardPorts, postCreateCommand, remoteUser, runArgs ...
// Mount gcloud configuration directory
"mounts": [
"source=/Users/myname/.config/gcloud,target=/gcp/config,type=bind,consistency=cached"
]
}
这可行,但如果我提交它,它会破坏其他人的设置。
如何创建到我本地定义的 vscode devcontainer 的绑定挂载,而不向 .devcontainer.json
添加条目?
解决方法
一种解决方法是将其转换为docker-compose 设置然后定义一个 docker-compose.developer-overrides.yml 文件,该文件不会被提交,但是是必需的。但这似乎是错误的解决方案,应该有一个我错过的设置覆盖。
另一种方法是挂载用户的主目录(vscode 用户指南显示了如何执行对于 Windows 和 Linux 用户,使用: “source=${localEnv:HOME}${localEnv:USERPROFILE},target=/host-home-folder,type=bind,consistency=cached”
...但是所有用户都必须将其 gcloud 配置安装在本地计算机的同一位置;我不确定这是否可能。
In this question it is recommended that .devcontainer.json
should be committed.
I agree, but for one problem. I need to bind mount a local directory into my devcontainer. That requires a local path that my colleagues won't have. The purpose is to mount my GCP credentials into my devcontainer for use with the gcloud CLI.
My .devcontainer.json looks like:
{
"image": "some/image",
// ... settings, extensions, forwardPorts, postCreateCommand, remoteUser, runArgs ...
// Mount gcloud configuration directory
"mounts": [
"source=/Users/myname/.config/gcloud,target=/gcp/config,type=bind,consistency=cached"
]
}
This works, but if I commit this it'll break everybody else's setups.
How can I create a bind mount to a vscode devcontainer that's defined locally by me, without adding an entry to .devcontainer.json
?
WORKAROUNDS
One workaround is to turn this into a docker-compose setup then define a docker-compose.developer-overrides.yml
file which doesn't get committed, but is required. But that seems like the wrong solution and there should be a settings override somewhere that I've missed.
Another is to mount the user's home directory (the vscode user guide shows how to do that for both windows and linux users using:"source=${localEnv:HOME}${localEnv:USERPROFILE},target=/host-home-folder,type=bind,consistency=cached"
...but then all users have to have their gcloud config installed in the same location in their local machine; I'm not sure if this is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将配置保存在 Docker 卷中。有一个示例:
devcontainer.json
文件init-host.sh
文件I keep my configs within Docker volumes. There is an example:
devcontainer.json
fileinit-host.sh
file