我想将我的 AWS 凭证文件以可移植的方式绑定到 DevContainer 中,以便在 VS Code 中进行开发,以便其他同事也可以在他们的机器上进行开发,所以我需要对我的主目录的相对引用。我尝试了这个 devcontainer.json:
{
"image": "ubuntu:latest",
"mounts": [{
"source": "$HOME/.aws",
"target": "/root/.aws",
"type": "bind"
}]
}
但它失败并出现错误:
[2025-03-30T23:22:08.292Z] docker:守护进程的错误响应:类型“bind”的挂载配置无效:挂载路径无效:'$HOME/.aws'挂载路径必须是绝对路径
在命令行上,此命令运行良好,因为 bash 扩展了变量:
docker run --mount type=bind,src=$HOME/.aws,dst=/root/.aws ubuntu:latest
PS:我的.aws/credentials
文件是由外部进程动态生成和刷新的。