4

I have a multi-stage Dockerfile. I want to configure VS Code Remote to build the dev stage of the Dockerfile rather than the last stage in the Dockerfile.

I'm pretty sure this configuration would go in the .devcontainer.json file. I've read through the .devcontainer.json reference: https://code.visualstudio.com/docs/remote/containers#_devcontainerjson-reference and tried runArgs, but these are the run-time args, not the build args.

I tried this:

{
        "dockerFile": "Dockerfile",
        "extensions": ["ms-python.python"],
        "runArgs": [
                "--target",
                "dev"
        ]
}

and:

{
        "dockerFile": "Dockerfile",
        "extensions": ["ms-python.python"],
        "buildArgs": [
                "--target",
                "dev"
        ]
}

When I used runArgs, I got Failed: Starting the development container because target is not a docker run option. When I tried buildArgs, the argument was apparently ignored, which makes sense since it isn't listed in the documentation.

4

3 回答 3

4

runArgs 指定要与“docker run”命令一起使用的参数。在这种情况下,我们需要将参数传递给“docker build”命令。

要指定构建参数,您需要使用“构建”属性。在您的示例中,您需要 devcontainer.json 文件包含:

"build": { 
    "target": "dev" 
},
于 2020-04-11T23:00:49.170 回答
3

您可以使用 Dev Container: Existing Docker Compose 模式。docker-compose 服务可以指定 Dockerfile 阶段。

于 2020-01-13T12:58:31.640 回答
0

我找到了解决方法。

我可以自己手动构建 Dockerfile:

docker build --target dev -t vizd .

然后使用image参数.devcontainer.json

{
    "image": "vizd",
    "extensions": ["ms-python.python"]
}

不完美,但可行。

于 2019-06-13T20:40:58.467 回答