devcontainers / devcontainers/cli

devcontainer build fails when using FROM scratch

Open
#239 4 comments 7 reactions 1 assignee Claimed by @chrmarti View on GitHub
bug
Dominant language
TypeScript
Stars
3k
Forks
457
Avg merge
13h 17m
Merged PRs (30d)
6

Description

Given a `.devcontainer/Dockerfile`:

```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`:

```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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.