Skip to content

bake in v0.23 doesn't support targets with dots #3360

Closed

Description

@yanwic

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

when dealing with a compose.yaml that defines additional build contexts, e.g.:

---
services:
    image1.0:
        image: test:latest
        build:
            context: .
            dockerfile: Dockerfile
    image2.0:
        image: test:dev
        build:
            context: ./2.0
            dockerfile: Dockerfile
            x-bake:
                contexts:
                    base: target:image1.0

bake fails to find the target image1.0:

docker buildx bake -f compose.yaml --progress plain
#0 building with "default" instance using docker driver

#1 [internal] load local bake definitions
#1 reading compose.yaml 331B / 331B done
#1 DONE 0.0s
ERROR: failed to find target image1.0

If we replace the dot with an underscore in the contexts section only:

---
services:
    image1.0:
        image: test:latest
        build:
            context: .
            dockerfile: Dockerfile
    image2.0:
        image: test:dev
        build:
            context: ./2.0
            dockerfile: Dockerfile
            x-bake:
                contexts:
                    base: target:image1_0

It will find the target and build fine

Expected behaviour

targets in compose files should be correctly identified even if they contain dots .

Actual behaviour

target cannot be found, unless the dots . are replaced with underscores _. This needs to happen in the x-bake.contexts only.

Buildx version

github.com/docker/buildx v0.23.0 28c90ea

Docker info

Client: Docker Engine - Community
 Version:    28.1.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.35.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 16
 Server Version: 28.1.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.6.87.2-microsoft-standard-WSL2
 Operating System: Ubuntu 22.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 7.602GiB
 Name: REDACTED
 ID: REDACTED
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: REDACTED
 Experimental: false
 Live Restore Enabled: false

Builders list

NAME/NODE       DRIVER/ENDPOINT   STATUS    BUILDKIT   PLATFORMS
default*        docker                                 
 \_ default      \_ default       running   v0.21.0    linux/amd64 (+4), linux/386
desktop-linux                     error                

Cannot load builder desktop-linux: protocol not available

Configuration

---
services:
    image1.0:
        image: test:latest
        build:
            context: .
            dockerfile: Dockerfile
    image2.0:
        image: test:dev
        build:
            context: ./2.0
            dockerfile: Dockerfile
            x-bake:
                contexts:
                    base: target:image1.0

leads to

docker buildx bake -f compose.yaml --progress plain
#0 building with "default" instance using docker driver

#1 [internal] load local bake definitions
#1 reading compose.yaml 331B / 331B done
#1 DONE 0.0s
ERROR: failed to find target image1.0

underscores work:

---
services:
    image1.0:
        image: test:latest
        build:
            context: .
            dockerfile: Dockerfile
    image2.0:
        image: test:dev
        build:
            context: ./2.0
            dockerfile: Dockerfile
            x-bake:
                contexts:
                    base: target:image1_0

Build logs


Additional info

No response

Activity

  1. yanwic commented on Aug 8, 2025

    @yanwic
    Author

    might be related to #1009

  2. crazy-max commented on Aug 8, 2025

    @crazy-max
    Member
                x-bake:
                    contexts:
                        base: target:image1.0

    Named contexts are now supported in the compose spec: https://docs.docker.com/reference/compose-file/build/#additional_contexts so you can avoid x-bake.

    Can you try with:

    services:
        image1.0:
            image: test:latest
            build:
                context: .
                dockerfile: Dockerfile
        image2.0:
            image: test:dev
            build:
                context: ./2.0
                dockerfile: Dockerfile
                additional_contexts:
                  base: service:image1.0
  3. crazy-max commented on Aug 8, 2025

    @crazy-max
    Member

    But still needs a fix in x-bake, will take look.

  4. yanwic commented on Aug 8, 2025

    @yanwic
    Author

    I just tried with additinal_contexts, but both variants service:image1.0 and target:image1.0 fail with:

    docker bake -f compose.yaml --debug
    [+] Building 0.0s (1/1) FINISHED                                                                                                                                                   docker:default
     => [internal] load local bake definitions                                                                                                                                                   0.0s
     => => reading compose.yaml 311B / 311B                                                                                                                                                      0.0s
    ERROR: failed to find target image1.0
    13327 v0.23.0 /usr/libexec/docker/cli-plugins/docker-buildx buildx bake -f compose.yaml --debug
    github.com/docker/buildx/bake.Config.target
            github.com/docker/buildx/bake/bake.go:669
    github.com/docker/buildx/bake.Config.ResolveTarget
            github.com/docker/buildx/bake/bake.go:640
    github.com/docker/buildx/bake.Config.loadLinks
            github.com/docker/buildx/bake/bake.go:497
    github.com/docker/buildx/bake.ReadTargets
            github.com/docker/buildx/bake/bake.go:251
    github.com/docker/buildx/commands.runBake
            github.com/docker/buildx/commands/bake.go:220
    github.com/docker/buildx/commands.bakeCmd.func1
            github.com/docker/buildx/commands/bake.go:468
    github.com/docker/cli/cli-plugins/plugin.RunPlugin.func1.1.2
            github.com/docker/cli@v28.0.4+incompatible/cli-plugins/plugin/plugin.go:65
    github.com/spf13/cobra.(*Command).execute
            github.com/spf13/cobra@v1.9.1/command.go:1015
    github.com/spf13/cobra.(*Command).ExecuteC
            github.com/spf13/cobra@v1.9.1/command.go:1148
    github.com/spf13/cobra.(*Command).Execute
            github.com/spf13/cobra@v1.9.1/command.go:1071
    github.com/docker/cli/cli-plugins/plugin.RunPlugin
            github.com/docker/cli@v28.0.4+incompatible/cli-plugins/plugin/plugin.go:80
    main.runPlugin
            github.com/docker/buildx/cmd/buildx/main.go:62
    main.run
            github.com/docker/buildx/cmd/buildx/main.go:76
    main.main
            github.com/docker/buildx/cmd/buildx/main.go:86
    runtime.main
            runtime/proc.go:272
    runtime.goexit
            runtime/asm_amd64.s:1700
    

    when using service:image1_0 it also fails but target:image1_0 works in this case.

  5. yanwic commented on Aug 8, 2025

    @yanwic
    Author

    I just noticed that, when printed out to JSON it shows all targets are converted to using underscores. This might be the root cause for this behaviour:

    docker bake -f compose.yaml --debug --print
    {
      "group": {
        "default": {
          "targets": [
            "image1_0",
            "image2_0"
          ]
        }
      },
      "target": {
        "image1_0": {
          "context": ".",
          "dockerfile": "Dockerfile",
          "tags": [
            "test:latest"
          ]
        },
        "image2_0": {
          "context": "2.0",
          "contexts": {
            "base": "target:image1_0"
          },
          "dockerfile": "Dockerfile",
          "tags": [
            "test:dev"
          ]
        }
      }
    }
    
  6. crazy-max commented on Aug 8, 2025

    @crazy-max
    Member

    Thanks for your feedback, I'm taking a look

  7. added this to the v0.27.0 milestone on Aug 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions