cli icon indicating copy to clipboard operation
cli copied to clipboard

devcontainer build fails when using FROM scratch

Open kklopfenstein opened this issue 3 years ago • 2 comments

Given a .devcontainer/Dockerfile:

FROM ubuntu as stage1

RUN apt-get update && apt-get install -y vim

FROM scratch as stage2

COPY --from=stage1 / /

RUN which vim

and a .devcontainer/devcontainer.json:

{
  "name": "my-image",
  "build": {
    "dockerfile": "Dockerfile"
  }
}

Building the devcontainer results in the following error:

devcontainer build --workspace-folder . --log-level trace
[10 ms] @devcontainers/cli 0.21.0. Node.js v16.18.0. darwin 21.6.0 arm64.
[10 ms] Start: Run: docker buildx version
[98 ms] Stop (88 ms): Run: docker buildx version
[98 ms] github.com/docker/buildx v0.9.1 ed00243a0ce2a0aee75311b06e32d33b44729689
[98 ms] 
[101 ms] Start: Run: docker inspect --type image scratch
[163 ms] Stop (62 ms): Run: docker inspect --type image scratch
[163 ms] resource: docker.io/library/scratch
[163 ms] id: scratch
[164 ms] version: latest
[164 ms] owner: library
[164 ms] namespace: library
[164 ms] registry: docker.io
[164 ms] path: library/scratch
[164 ms] No oauth authentication credentials found.
[164 ms] url: https://auth.docker.io/token?scope=repository:library/scratch:pull&service=registry.docker.io
[429 ms] manifest url: https://registry-1.docker.io/v2/library/scratch/manifests/latest
[690 ms] Error fetching image details: No manifest found for docker.io/library/scratch.
[691 ms] Start: Run: docker pull scratch
Using default tag: latest
Error response from daemon: 'scratch' is a reserved name
[835 ms] Stop (144 ms): Run: docker pull scratch
[835 ms] []
[835 ms] Error: No such image: scratch

{"outcome":"error","message":"Command failed: docker inspect --type image scratch","description":"An error occurred building the container."}

However, building the Dockerfile using docker build works fine. It seems that the devcontainer CLI doesn't support FROM scratch within a Dockerfile.

kklopfenstein avatar Oct 20 '22 18:10 kklopfenstein

Thanks for the report. I was unfamiliar with the scratch image.

It appears that I can't directly pull it either

image

joshspicer avatar Oct 21 '22 20:10 joshspicer

One of the use-cases for using FROM scratch is squashing image layers to reduce image size for use in a base image.

kklopfenstein avatar Oct 24 '22 15:10 kklopfenstein

Same issue (persists) with Code 1.80.0/Dev Containers v0.299.0 on Fedora 38 w/Podman:

devcontainer cli ignores scratch for the reserved empty name it is and tries to pull it first.

[515 ms] Start: Run: /usr/share/code/code --ms-enable-electron-run-as-node /home/theloeki/.vscode/extensions/ms-vscode-remote.remote-containers-0.299.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/theloeki/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --docker-path podman --docker-compose-path podman-compose --container-session-data-folder /tmp/devcontainers-1694afa3-a584-4f18-9317-1d3b9adf84301688917548877 --workspace-folder=example --workspace-mount-consistency consistent --id-label devcontainer.local_folder=example --id-label devcontainer.config_file=example --log-level debug --log-format json --config example --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[691 ms] @devcontainers/cli 0.46.0. Node.js v16.17.1. linux 6.3.11-200.fc38.x86_64 x64.
[691 ms] Start: Run: podman buildx version
[742 ms] buildah 1.30.0
[742 ms] 
[742 ms] Start: Resolving Remote
[744 ms] Start: Run: git rev-parse --show-cdup
[806 ms] Start: Run: podman ps -q -a --filter label=devcontainer.local_folder=example --filter label=devcontainer.config_file=example
[835 ms] Start: Run: podman inspect --type image scratch
[1177 ms] Start: Run: docker-credential-secret get
[2138 ms] Error fetching image details: No manifest found for docker.io/library/scratch.
[2139 ms] Start: Run: podman pull scratch
? Please select an image: 
  ▸ registry.fedoraproject.org/scratch:latest
    registry.access.redhat.com/scratch:latest
    docker.io/library/scratch:latest
    quay.io/scratch:latest
 

The-Loeki avatar Jul 09 '23 16:07 The-Loeki