dart vscode containerEnv在装载中不起作用

jhiyze9q  于 2023-03-21  发布在  Vscode
关注(0)|答案(1)|浏览(115)

我使用的是vscode命令远程包含:打开容器中的文件夹...
我正在尝试将一个文件绑定到docker容器中。
~/.config/dart/pub-tokens.json
主机文件在我的HOME目录下,我需要将它挂载到容器HOME目录中的同一位置。
下面是我从vscode devcontainer.json发出的mount命令

"mounts": [
        "source=${localEnv:HOME}/.config/dart/pub-tokens.json,target=${containerEnv:HOME}/.config/dart/pub-tokens.json,type=bind,consistency=cached",
        
    ]

注意目标子句中的“containerEnv”。
通过vscode Remote启动容器-包含:“打开容器中的文件夹...”会产生以下错误:(为了便于阅读,我添加了一些换行符)

Start: Run: docker run --sig-proxy=false -a STDOUT -a STDERR 
--mount type=bind,source=/home/bsutton/git/onepub/onepub,target=/workspaces/onepub 
--mount source=/home/bsutton/.config/dart/pub-tokens.json,target=${containerEnv:HOME}/.config/dart/pub-tokens.json,type=bind,consistency=cached 
--mount source=/home/bsutton/.onepub/onepub.yaml,target=${containerEnv:HOME}/.onepub/onepub.yaml,type=bind,consistency=cached 
--mount type=volume,src=vscode,dst=/vscode -l devcontainer.local_folder=/home/bsutton/git/onepub/onepub 
--entrypoint /bin/sh vsc-onepub-7ff341664d5755895634c2f74983ff45-uid -c echo Container started

docker: Error response from daemon: 
invalid mount config for type "bind": invalid mount path: '${containerEnv:HOME}/.config/dart/pub-tokens.json' mount path must be absolute.

看起来vscode没有展开containerEnv。
如果我用localEnv替换containerEnv,它确实会被展开(但路径错误)。
即以下工程:

"mounts": [
        "source=${localEnv:HOME}/.config/dart/pub-tokens.json,target=${localEnv:HOME}/.config/dart/pub-tokens.json,type=bind,consistency=cached",
        
    ]

下面是完整的devcontainer.json

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/ubuntu
{
    "name": "Ubuntu",
    "build": {
        "dockerfile": "Dockerfile",
        // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04
        // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon.
        "args": { "VARIANT": "ubuntu-22.04" }
    },

    // 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": "uname -a",

    // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode",
    "features": {
        "git": "latest",
        "github-cli": "latest"
    },
    "mounts": [
        "source=${localEnv:HOME}/.config/dart/pub-tokens.json,target=${containerEnv:HOME}/.config/dart/pub-tokens.json,type=bind,consistency=cached",
        "source=${localEnv:HOME}/.onepub/onepub.yaml,target=${containerEnv:HOME}/.onepub/onepub.yaml,type=bind,consistency=cached"
    ]
    
}
5cg8jx4n

5cg8jx4n1#

我也遇到过这个问题,但是经过思考,在创建容器环境变量之前就展开它是无法令人满意的,正如下面的注解所示:
挂载点是在创建容器时应用的,但是容器变量(containerEnv)只有在容器创建后才被替换,这是因为只有在容器创建后我们才能检查容器的环境变量。

  • ${containerEnv:TEST_VAR}不适用于装载编号7147

我希望事情至少可以回到Dockerfile中静态定义的ENV,但这里似乎不是这样。

相关问题