0

I've been working in a devcontainer doing C++ development, I rebuilt the container and it failed to build. I've since tried another container and it also won't build. I know the devcontainer files and dockerfile are unchanged from when this worked.

When I first noticed I opened another devcontainer on a similar repo - and it started the container fine. When I tried to rebuild it I got the same error.

The first error is

ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = target stage dev_containers_target_stage could not be found

In context

 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
[2022-10-07T21:44:13.502Z] [+] Building 1.8s (7/7) FINISHED                                                
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => => transferring dockerfile: 1.12kB                                     0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4               1.5s
[2022-10-07T21:44:13.502Z]  => [auth] docker/dockerfile:pull token for registry-1.docker.io           0.0s
 => CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => [internal] load .dockerignore                                          0.0s
ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = target stage dev_containers_target_stage could not be found
[2022-10-07T21:44:13.511Z] Stop (2075 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-david/container-features/0.19.0-1665179051412/Dockerfile-with-features -t vsc-components-e3528559c8b219e2efe0f837299d4fa8 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-david/container-features/0.19.0-1665179051412 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/david/Repos/Arabica/Components/.devcontainer
[2022-10-07T21:44:13.512Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-david/container-features/0.19.0-1665179051412/Dockerfile-with-features -t vsc-components-e3528559c8b219e2efe0f837299d4fa8 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-david/container-features/0.19.0-1665179051412 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/david/Repos/Arabica/Components/.devcontainer
[2022-10-07T21:44:13.512Z]     at fD (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:298:1633)
[2022-10-07T21:44:13.513Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-10-07T21:44:13.513Z]     at async wd (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:297:1958)
[2022-10-07T21:44:13.513Z]     at async sC (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:297:894)
[2022-10-07T21:44:13.513Z]     at async bD (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:303:2020)
[2022-10-07T21:44:13.513Z]     at async ys (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:303:3182)
[2022-10-07T21:44:13.513Z]     at async UL (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:423:10319)
[2022-10-07T21:44:13.513Z]     at async ML (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:423:10075)
[2022-10-07T21:44:13.515Z] Stop (3813 ms): Run in Host: /home/david/.vscode-server/bin/64bbfbf67ada9953918d72e1df2f4d8e537d340e/node /home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/david/Repos/Arabica/Components --workspace-mount-consistency cached --id-label devcontainer.local_folder=\\wsl.localhost\Ubuntu\home\david\Repos\Arabica\Components --log-level debug --log-format json --config /home/david/Repos/Arabica/Components/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-10-07T21:44:13.515Z] Exit code 1
[2022-10-07T21:44:13.518Z] Command failed: /home/david/.vscode-server/bin/64bbfbf67ada9953918d72e1df2f4d8e537d340e/node /home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/david/Repos/Arabica/Components --workspace-mount-consistency cached --id-label devcontainer.local_folder=\\wsl.localhost\Ubuntu\home\david\Repos\Arabica\Components --log-level debug --log-format json --config /home/david/Repos/Arabica/Components/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-10-07T21:44:13.518Z] Exit code 1

For reference the devcontainer is

// 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.2/containers/cpp
{
    "name": "Components",
    "build": {
        "dockerfile": "Dockerfile"
    },
    "workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspace,type=bind,consistency=cached",
    "workspaceFolder": "/workspace/Components",
    "runArgs": [
        "--cap-add=SYS_PTRACE",
        "--security-opt",
        "seccomp=unconfined"
    ],
    // Configure tool-specific properties.
    "customizations": {
        // Configure properties specific to VS Code.
        "vscode": {
            // Add the IDs of extensions you want installed when the container is created.
            "extensions": [
                "ms-vscode.cpptools",
                "ms-vscode.cpptools-extension-pack",
                "ms-vscode.cpptools-themes",
                "ms-vscode.makefile-tools",
                "jeff-hykin.better-cpp-syntax",
                "bneumann.cpputest-test-adapter"
            ]
        }
    },
    // Use 'postCreateCommand' to run commands after the container is created. "postStartCommand": "git config --global core.sshCommand /usr/bin/ssh",
    // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    "remoteUser": "vscode"
}

Dockerfile

FROM davidcozens/cpputest:4

ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \

I have so far tried: Wipe out the docker cache of images and cleaned out containers. I've updated my ubuntu distro in wsl2, I've ensured docker is up to date. I've updated windows - I'm running the latest version of windows 11.

David
  • 1
  • 2

1 Answers1

0

The issue is the final line of the Dockerfile:

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \

Docker may have previously supported a final trailing slash in a Dockerfile RUN statement, but it appears to no longer be supported. (I'm not sure when this happened, but I'm on Docker 20.10.21 and it's no longer supported.)

This trailing slash appears to interfere with the following FROM statement in the VS Code generated Dockerfile-with-features file, which will look something like this:

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
    && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \


FROM $_DEV_CONTAINERS_BASE_IMAGE AS dev_containers_target_stage

If that FROM statement is no longer able to be read, then the error message makes much more sense:

target stage dev_containers_target_stage could not be found

Remove the trailing \ in the Dockerfile and it should work.

tjdett
  • 1,703
  • 1
  • 18
  • 23