Skip to content

[BUG] built images are not added to bake targets when using up #12923

Closed
@israelglar

Description

@israelglar

Description

when running docker compose up if a build dependency is already built it doesn't get loaded up into bake targets when trying to build

Steps To Reproduce

services:
  firstbuild:
    build:
      dockerfile_inline: |
        FROM alpine
      additional_contexts:
        dep1: service:dep1
    entrypoint: ["echo", "Hello from firstbuild"]
    depends_on:
      - dep1

  secondbuild:
    build:
      dockerfile_inline: |
        FROM alpine
      additional_contexts:
        dep1: service:dep1
    entrypoint: ["echo", "Hello from secondbuild"]
    depends_on:
      - dep1

  dep1:
    build:
      dockerfile_inline: |
        FROM alpine
    entrypoint: ["echo", "Hello from dep1"]

Run docker compose up firstbuild, it will build fine and then run docker compose secondbuild it will error out with failed to find target dep1

Compose Version

Docker Compose version v2.37.0-3-g8151b5928

Docker Environment

Client: Docker Engine - Community
 Version:    28.2.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.24.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.37.0-3-g8151b5928
    Path:     /home/user/.docker/cli-plugins/docker-compose

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 34
 Server Version: 28.2.2
 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: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 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:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-60-generic
 Operating System: Ubuntu 22.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 31.06GiB
 ID: 2b2e89ad-9b8a-4a55-987b-9e9edf5b2b94
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

running with --verbose we get this:

docker compose --verbose up firstbuild

DEBU[0000] bake build config:
{
  "group": {
    "default": {
      "targets": [
        "dep1",
        "firstbuild"
      ]
    }
  },
  "target": {
    "dep1": {
      "context": "/home/israel/projects/compose-test",
      "dockerfile-inline": "FROM alpine\n",
      "tags": [
        "compose-test-dep1"
      ],
      "output": [
        "type=docker,load=true,push=false"
      ]
    },
    "firstbuild": {
      "context": "/home/israel/projects/compose-test",
      "contexts": {
        "dep1": "target:dep1"
      },
      "dockerfile-inline": "FROM alpine\n",
      "tags": [
        "compose-test-firstbuild"
      ],
      "output": [
        "type=docker,load=true,push=false"
      ]
    }
  }
}

docker compose --verbose up secondbuild

DEBU[0000] bake build config:
{
  "group": {
    "default": {
      "targets": [
        "secondbuild"
      ]
    }
  },
  "target": {
    "secondbuild": {
      "context": "/home/israel/projects/compose-test",
      "contexts": {
        "dep1": "target:dep1"
      },
      "dockerfile-inline": "FROM alpine\n",
      "tags": [
        "compose-test-secondbuild"
      ],
      "output": [
        "type=docker,load=true,push=false"
      ]
    }
  }
}

The error doesn't happen when running docker compose up --build secondbuild or docker compose build secondbuild because both change the pull_policy to "build" for all services

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions