microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.67k stars 292 forks source link

Latest version of Remote Containers causes an error when building my devcontainer #7319

Open PaulHiemstra opened 2 years ago

PaulHiemstra commented 2 years ago

The latest version of remote containers no longer allows me to build a container that is externally defined in a dockerfile. The issue is fixed by going back to the previous version of the plugin.

Steps to Reproduce:

  1. Create new directory and drop the .devcontainer.json file in the root

    {
    "name": "Tensorflow with Jupyter (GPU enabled)",
    "build": { "dockerfile": "docker/Dockerfile" },
    "forwardPorts": [8888],
    "postStartCommand": "nohup bash -c 'jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --NotebookApp.token=jupdevtoken &'",
    "runArgs": [
    "--gpus",
    "all"
    ],
    "extensions": [
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-toolsai.jupyter"
    ]
    }
  2. Create a docker subdirectory, drop Dockerfile in that subdir

FROM tensorflow/tensorflow:latest-gpu-jupyter

RUN pip install pandas\
    sklearn\
    seaborn\
  1. Start VS Code and restart the directory in the container
  2. The following error occurs when building the container (full log in error.log
    
    error: failed to solve: rpc error: code = Unknown desc = failed to solve with fr
    ontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code    
    = Unknown desc = target stage dev_containers_target_stage could not be found


Does this issue occur when you try this locally?: Yes
Does this issue occur when you try this locally and all extensions are disabled?: Yes
chrmarti commented 2 years ago

What do you get for docker buildx ls? If the current builder (marked with *) is not the default one, try switching to it with docker buildx use default and retry.

chrmarti commented 2 years ago

Sorry, ignore the previous comment, I misread the error message.

Could you append C:\Users\PH0110~1\AppData\Local\Temp\devcontainercli\container-features\0.19.0-1665383336028\Dockerfile-with-features mentioned in the log?

PaulHiemstra commented 2 years ago

Here is the Dockerfile you requested: Dockerfile-with-features.txt

# syntax=docker/dockerfile:1.4
ARG _DEV_CONTAINERS_BASE_IMAGE=placeholder
FROM tensorflow/tensorflow:latest-gpu-jupyter AS dev_container_auto_added_stage_label
WORKDIR "/tmp"

RUN pip install pandas\
    sklearn\
    seaborn\
    mlflow\

FROM $_DEV_CONTAINERS_BASE_IMAGE AS dev_containers_target_stage

USER root

COPY --from=dev_containers_feature_content_source . /tmp/build-features/

ARG _DEV_CONTAINERS_IMAGE_USER=root
USER $_DEV_CONTAINERS_IMAGE_USER

LABEL devcontainer.metadata="{\"postStartCommand\":\"nohup bash -c 'jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root --NotebookApp.token=jupdevtoken &'\",\"customizations\":{\"vscode\":{\"extensions\":[\"ms-python.python\",\"ms-python.vscode-pylance\",\"ms-toolsai.jupyter\"]}},\"forwardPorts\":[8888,5000]}"
chrmarti commented 2 years ago

The dev_containers_target_stage stage is there. Not sure why --target dev_containers_target_stage would not work.

PaulHiemstra commented 2 years ago

The issue must be in the recently added code, the release of a month ago does not show this issue.

PaulHiemstra commented 2 years ago

Here is a remote containers logfile of the version that works. no_error.log.log

What strikes me as odd is that there is no mention of Dockerfile-with-features, so this seems to be a new addition that does not work correctly.

AlexisLessard commented 2 years ago

We're having the same issue, using this dockerfile:

# [Choice] .NET version: 6.0, 5.0, 3.1, 6.0-bullseye, 5.0-bullseye, 3.1-bullseye, 6.0-focal, 5.0-focal, 3.1-focal
ARG VARIANT=6.0
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT}

#Install oc and kubectl client
RUN wget https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable/openshift-client-linux.tar.gz \
    && tar -zxvf openshift-client-linux.tar.gz --directory /tmp/ \
    && cp /tmp/oc /tmp/kubectl /usr/local/sbin \
    && chmod +x /usr/local/sbin/oc && chmod +x /usr/local/sbin/kubectl \
    && rm -f /tmp/oc && rm -f /tmp/kubectl &&  rm -f /tmp/README.md

#Install ReportGenerator
RUN dotnet tool install -g dotnet-reportgenerator-globaltool \
    && dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools \
    && dotnet new tool-manifest --name ReportGenerator \
    && dotnet tool install dotnet-reportgenerator-globaltool \

VSCode Version:1.72.1 Local OS Version: Windows 10 10.0.19044 Remote OS Version: Ubuntu 20.04 (WSL2) Remote Extension/Connection Type: Container running in Docker desktop via the wsl2 backend. Folder is located in the WSL2 workspace, not on the windows file system.

tjdett commented 2 years ago

I had a similar problem. The issue is this line:

RUN pip install pandas\
    sklearn\
    seaborn\
    mlflow\

Docker may have previously supported a final trailing slash in a build file, 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.

Just remove the slash and it should work:

RUN pip install pandas\
    sklearn\
    seaborn\
    mlflow
chrmarti commented 2 years ago

@PaulHiemstra Does it work when you remove the trailing \ from your Dockerfile?

AlexisLessard commented 2 years ago

@chrmarti Seemed to do it for me! I can build my devcontainer again!

Any idea on why that is? What changed between 1.70 and 1.72 that created this problem?

walsha2 commented 2 years ago

Does it work when you remove the trailing \ from your Dockerfile?

@chrmarti Can confirm as well. Removing the trailing \ from one of my Dockerfile commands (which previously was not an issue) worked.

Here is the error caused by that trailing \, same as @PaulHiemstra:

[2022-11-04T20:19:50.061Z] ERROR: failed to solve: rpc error: code = Unknown desc = failed 
to solve with frontend dockerfile.v0: failed to create LLB definition: 
target stage dev_containers_target_stage could not be found

@tjdett good find. Running on Docker version 20.10.17, build 100c701, M1 Macbook Pro

sanmai-NL commented 1 year ago

What's this name dev_containers_target_stage about? I also see this referenced, but that stage doesn‘t exist in my Dockerfile.

teom10 commented 1 year ago

I had a similar problem. The issue is this line:

RUN pip install pandas\
    sklearn\
    seaborn\
    mlflow\

Docker may have previously supported a final trailing slash in a build file, 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.

Just remove the slash and it should work:

RUN pip install pandas\
    sklearn\
    seaborn\
    mlflow

this helped me solve the problem

armaanPy commented 1 year ago

What's this name dev_containers_target_stage about? I also see this referenced, but that stage doesn‘t exist in my Dockerfile.

I'm also wondering the same thing. Anyone know?

chrmarti commented 1 year ago

On dev_containers_target_stage: We write a new Dockerfile with this additional stage to add the "features" configured in the devcontainer.json and metadata to the final image.

akutruff commented 1 year ago

Just hit this myself using the default generated devcontainer.json without a Dockerfile

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
    "name": "Node.js & TypeScript",
    // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
    "image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
    "features": {
        "ghcr.io/devcontainers/features/git-lfs:1": {}
    }

    // Features to add to the dev container. More info: https://containers.dev/features.
    // "features": {},

    // 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": "yarn install",

    // Configure tool-specific properties.
    // "customizations": {},

    // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
    // "remoteUser": "root"
}
[2023-01-10T15:52:33.840Z] * Processing feature: ghcr.io/devcontainers/features/git-lfs:1
[2023-01-10T15:52:33.841Z] No authentication credentials found for registry 'ghcr.io'.
[2023-01-10T15:52:33.841Z] No authentication credentials found for registry 'ghcr.io'.
[2023-01-10T15:52:34.245Z] * Fetching feature: git-lfs_1_oci
[2023-01-10T15:52:34.247Z] No authentication credentials found for registry 'ghcr.io'.
[2023-01-10T15:52:34.247Z] No authentication credentials found for registry 'ghcr.io'.
[2023-01-10T15:52:34.620Z] Start: Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.26.0-1673365953781 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/typescript-node:0-18 --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-pricey-f7328750c5899a199e56d06dd6cc1165-features -f /tmp/devcontainercli-root/container-features/0.26.0-1673365953781/Dockerfile.extended /tmp/devcontainercli-root/empty-folder
[2023-01-10T15:52:34.866Z] 
[2023-01-10T15:52:34.866Z] [+] Building 0.0s (0/0)                                                         
[2023-01-10T15:52:34.967Z] [+] Building 0.0s (0/1)                                                         
 => [internal] load build definition from Dockerfile.extended              0.0s
 => => transferring dockerfile: 39B                                        0.0s
[2023-01-10T15:52:35.103Z] [+] Building 0.2s (2/3)                                                         
 => [internal] load build definition from Dockerfile.extended              0.0s
 => => transferring dockerfile: 1.56kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
[2023-01-10T15:52:35.103Z]  => resolve image config for docker.io/docker/dockerfile:1.4               0.0s
[2023-01-10T15:52:35.253Z] [+] Building 0.3s (2/3)                                                         
 => [internal] load build definition from Dockerfile.extended              0.0s
 => => transferring dockerfile: 1.56kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
 => resolve image config for docker.io/docker/dockerfile:1.4               0.2s
[2023-01-10T15:52:35.257Z] Container server: {
  message: 'write EPIPE',
  name: 'Error',
  stack: 'Error: write EPIPE\n' +
    '\tat afterWriteDispatched (node:internal/stream_base_commons:160:15)\n' +
    '\tat writeGeneric (node:internal/stream_base_commons:151:3)\n' +
    '\tat Socket._writeGeneric (node:net:795:11)\n' +
    '\tat Socket._write (node:net:807:8)\n' +
    '\tat writeOrBuffer (node:internal/streams/writable:389:12)\n' +
    '\tat _write (node:internal/streams/writable:330:10)\n' +
    '\tat Writable.write (node:internal/streams/writable:334:10)\n' +
    '\tat c:\\Users\\andyk\\.vscode\\extensions\\ms-vscode-remote.remote-containers-0.269.0\\dist\\extension\\extension.js:87:219\n' +
    '\tat new Promise (<anonymous>)\n' +
    '\tat Fe (c:\\Users\\andyk\\.vscode\\extensions\\ms-vscode-remote.remote-containers-0.269.0\\dist\\extension\\extension.js:86:1504)\n' +
    '\tat async vk (c:\\Users\\andyk\\.vscode\\extensions\\ms-vscode-remote.remote-containers-0.269.0\\dist\\extension\\extension.js:67:709)\n' +
    '\tat async yk (c:\\Users\\andyk\\.vscode\\extensions\\ms-vscode-remote.remote-containers-0.269.0\\dist\\extension\\extension.js:67:79)\n' +
    '\tat async Object.rpc (c:\\Users\\andyk\\.vscode\\extensions\\ms-vscode-remote.remote-containers-0.269.0\\dist\\extension\\extension.js:83:901)'
}
[2023-01-10T15:52:35.277Z] [+] Building 0.3s (3/3) FINISHED                                                
 => [internal] load build definition from Dockerfile.extended              0.0s
 => => transferring dockerfile: 1.56kB                                     0.0s
 => [internal] load .dockerignore                                          0.1s
 => => transferring context: 2B                                            0.0s
 => ERROR resolve image config for docker.io/docker/dockerfile:1.4         0.2s
------
 > resolve image config for docker.io/docker/dockerfile:1.4:
[2023-01-10T15:52:35.278Z] ------
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 = error getting credentials - err: exit status 255, out: ``
[2023-01-10T15:52:35.282Z] Stop (662 ms): Run: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.26.0-1673365953781 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/typescript-node:0-18 --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-pricey-f7328750c5899a199e56d06dd6cc1165-features -f /tmp/devcontainercli-root/container-features/0.26.0-1673365953781/Dockerfile.extended /tmp/devcontainercli-root/empty-folder
[2023-01-10T15:52:35.283Z] Error: Command failed: docker buildx build --load --build-context dev_containers_feature_content_source=/tmp/devcontainercli-root/container-features/0.26.0-1673365953781 --build-arg _DEV_CONTAINERS_BASE_IMAGE=mcr.microsoft.com/devcontainers/typescript-node:0-18 --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp --target dev_containers_target_stage -t vsc-pricey-f7328750c5899a199e56d06dd6cc1165-features -f /tmp/devcontainercli-root/container-features/0.26.0-1673365953781/Dockerfile.extended /tmp/devcontainercli-root/empty-folder
[2023-01-10T15:52:35.283Z]     at Kne (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1865:1355)
[2023-01-10T15:52:35.283Z]     at x7 (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1865:1291)
[2023-01-10T15:52:35.283Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2023-01-10T15:52:35.283Z]     at async oie (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1871:2093)
[2023-01-10T15:52:35.283Z]     at async qf (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1871:3239)
[2023-01-10T15:52:35.283Z]     at async Mse (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1995:16211)
[2023-01-10T15:52:35.283Z]     at async Lse (/root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js:1995:15965)
[2023-01-10T15:52:35.318Z] Stop (2683 ms): Run in container: node /root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /workspaces/pricey --workspace-mount-consistency cached --id-label vsch.local.repository=git@github.com:kutruff/pricey.git --id-label vsch.local.repository.volume=pricey --id-label vsch.local.repository.folder=pricey --log-level debug --log-format json --config /workspaces/pricey/.devcontainer/devcontainer.json --override-config /tmp/devcontainer-c17cc4e0-2474-4147-8001-cedbfde366de.json --default-user-env-probe loginInteractiveShell --build-no-cache --remove-existing-container --mount type=volume,source=pricey,target=/workspaces,external=true --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default off --mount-workspace-git-root true
[2023-01-10T15:52:35.318Z] Exit code 1
[2023-01-10T15:52:35.318Z] Start: Run: docker rm -f 7b02b4bc040ff78533b9d8415090be181fca5dac153976f433ad5bdd059ff4f6
[2023-01-10T15:52:35.322Z] Command failed: node /root/.vscode-remote-containers/dist/dev-containers-cli-0.269.0/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /workspaces/pricey --workspace-mount-consistency cached --id-label vsch.local.repository=git@github.com:kutruff/pricey.git --id-label vsch.local.repository.volume=pricey --id-label vsch.local.repository.folder=pricey --log-level debug --log-format json --config /workspaces/pricey/.devcontainer/devcontainer.json --override-config /tmp/devcontainer-c17cc4e0-2474-4147-8001-cedbfde366de.json --default-user-env-probe loginInteractiveShell --build-no-cache --remove-existing-container --mount type=volume,source=pricey,target=/workspaces,external=true --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default off --mount-workspace-git-root true
[2023-01-10T15:52:35.323Z] Exit code 1
[2023-01-10T15:52:35.521Z] Stop (5283 ms): Run in container: /bin/sh
[2023-01-10T15:52:35.536Z] Stop (5036 ms): Run in container: /bin/sh
[2023-01-10T15:52:35.536Z] Container server terminated (code: 137, signal: null).
[2023-01-10T15:52:35.909Z] Stop (591 ms): Run: docker rm -f 7b02b4bc040ff78533b9d8415090be181fca5dac153976f433ad5bdd059ff4f6
[2023-01-10T15:52:55.504Z] Start: Run: docker version --format {{.Server.APIVersion}}
[2023-01-10T15:52:55.703Z] Stop (199 ms): Run: docker version --format {{.Server.APIVersion}}
[2023-01-10T15:52:55.704Z] 1.41
chrmarti commented 1 year ago

@akutruff This seems to be a different problem, could you open a new issue for this?