docker / docker/buildx

Unable to use library/* as build context and override it from bake files

Open
#2,328 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status/triage
Dominant language
Go
Stars
4.5k
Forks
682
Avg merge
2d 14h
Merged PRs (30d)
29

Description

Contributing guidelines
I've found a bug and checked that ...
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem
Description

FROM library/golang (for example) always resolves to docker.io/library/golang:latest even if I set library/golang to something like docker-library://library/golang:1.22. The same applies to --from=library/golang

Expected behaviour

I should be able to override library/* with anything, especially since docker buildx build --context library/golang=... works as expected

Actual behaviour

As stated in the description

Buildx version

github.com/docker/buildx v0.13.0 0de5f1c

Docker info

No response

Builders list
NAME/NODE     DRIVER/ENDPOINT   STATUS    BUILDKIT   PLATFORMS
default*      docker                                 
 \_ default    \_ default       running   v0.12.5    linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/386
Configuration

# Dockerfile
FROM scratch
COPY --from=library/golang /usr/local/go /go/library
COPY --from=bitnami/golang /opt/bitnami/go /go/bintami


# docker-bake.hcl
target default {
  contexts = {
    "library/golang" = "docker-image://library/golang:1.22"
    "bitnami/golang" = "docker-image://bitnami/golang:1.22"
  }
}


docker buildx bake --progress plain -f docker-bake.hcl

Build logs
#0 building with "default" instance using docker driver

#1 [internal] load local bake definitions
#1 reading docker-bake.hcl 158B / 158B done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 158B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/golang:latest
#3 ...

#4 [context bitnami/golang] load metadata for bitnami/golang:1.22
#4 DONE 0.4s

#3 [internal] load metadata for docker.io/library/golang:latest
#3 DONE 0.4s

#5 [internal] load .dockerignore
#5 transferring context: 2B done
#5 DONE 0.0s

#6 FROM docker.io/library/golang:latest@sha256:34ce21a9696a017249614876638ea37ceca13cdd88f582caad06f87a8aa45bf3
#6 DONE 0.0s

#7 [context bitnami/golang] bitnami/golang:1.22
#7 resolve docker.io/bitnami/golang:1.22
#7 resolve docker.io/bitnami/golang:1.22 0.3s done
#7 DONE 0.3s

#8 [stage-0 1/2] COPY --from=library/golang /usr/local/go /go/library
#8 CACHED

#9 [stage-0 2/2] COPY --from=bitnami/golang /opt/bitnami/go /go/bintami
#9 CACHED

#10 exporting to image
#10 exporting layers done
#10 writing image sha256:1bd6490245f856f9de92659e55cce8186534a241d96847ba95fa010d7c5648b7 done
#10 DONE 0.0s
Additional info

$ docker buildx build --progress plain --build-context library/golang=docker-image://library/golang:1.22 --build-context bitnami/golang=docker-image://bitnami/golang:1.22 .
#0 building with "default" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 158B done
#1 DONE 0.0s

#2 [context golang] load metadata for library/golang:1.22
#2 ...

#3 [context bitnami/golang] load metadata for bitnami/golang:1.22
#3 DONE 0.8s

#2 [context golang] load metadata for library/golang:1.22
#2 DONE 0.8s

#4 [internal] load .dockerignore
#4 transferring context: 2B done
#4 DONE 0.0s

#5 [context bitnami/golang] bitnami/golang:1.22
#5 resolve docker.io/bitnami/golang:1.22
#5 resolve docker.io/bitnami/golang:1.22 0.3s done
#5 DONE 0.3s

#6 [context golang] library/golang:1.22
#6 resolve docker.io/library/golang:1.22 0.4s done
#6 DONE 0.4s

#7 [stage-0 1/2] COPY --from=library/golang /usr/local/go /go/library
#7 CACHED

#8 [stage-0 2/2] COPY --from=bitnami/golang /opt/bitnami/go /go/bintami
#8 CACHED

#9 exporting to image
#9 exporting layers done
#9 writing image sha256:1bd6490245f856f9de92659e55cce8186534a241d96847ba95fa010d7c5648b7 done
#9 DONE 0.0s

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided Dockerfile and docker-bake.hcl using docker buildx bake and the equivalent --build-context command. Trace how FROM and COPY --from resolve named contexts, then verify that a library/golang context override is honored while the bitnami/golang case remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, dockerfile, go
Domain
build-system, cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.