Skip to content

[BUG] docker compose run triggers an unwanted rebuild (regression in v2.37.2) #12966

@Tycale

Description

@Tycale

Description

Affected versions

Component Works (v2.37.1) Fails (v2.37.2)
Docker Compose

Since Docker Compose v2.37.2, docker compose run seems to always rebuilds a service that has both an image: tag and a build: section, even when the tagged image is already present locally. Earlier versions (≤ v2.37.1) correctly skipped the build. This regression breaks CI pipelines that pre-build images with secret build args and expect the run phase to start the container without rebuilding.

Steps To Reproduce

Steps to reproduce

# 1 – Build and load the image locally
docker buildx build \
  --load \
  -f src/path/Dockerfile.api-core \
  --target base \
  -t X-api .

# 2 – docker-compose.yml
cat <<'YML' > docker-compose.yml
services:
  core-test:
    image: X-api          # Matches the tag built above
    build:
      context: .
      dockerfile: src/path/Dockerfile.api-core
      target: base
YML

# 3 – Run the service
docker compose run --rm core-test echo OK

Expected behavior (v2.37.1)

docker compose run detects the local image X-api and starts the container without any build.

Actual behavior (v2.37.2)

Compose always launches a new build for core-test.

Why is it an issue ?

In my CI, it fails because secret build-args (e.g. Y_SECRET) are only available during the initial build step.

Compose Version

/

Docker Environment

## Env
Docker version

/usr/bin/docker version
  Client:
   Version:           25.0.4
   API version:       1.44
   Go version:        go1.21.8
   Git commit:        1a576c5
   Built:             Wed Mar  6 16:32:02 2024
   OS/Arch:           linux/amd64
   Context:           default
  Server: Docker Engine - Community
   Engine:
    Version:          28.2.2
    API version:      1.50 (minimum version 1.24)
    Go version:       go1.24.3
    Git commit:       45873be
    Built:            Fri May 30 11:52:20 2025
    OS/Arch:          linux/amd64
    Experimental:     false
   containerd:
    Version:          v1.7.27
    GitCommit:        05044ec0a9a75232cad458027ca83437aae3f4da
   runc:
    Version:          1.2.6
    GitCommit:        v1.2.6-0-ge89a[29](https://github.com/PII/PII/actions/runs/15829363608/job/44617836286?pr=26309#step:7:31)9
   docker-init:
    Version:          0.19.0
    GitCommit:        de40ad0
  /usr/bin/docker info
  Client:
   Version:    25.0.4
   Context:    default
   Debug Mode: false
   Plugins:
    buildx: Docker Buildx (Docker Inc.)
      Version:  v0.13.1
      Path:     /usr/local/lib/docker/cli-plugins/docker-buildx
    compose: Docker Compose (Docker Inc.)
      Version:  v2.37.1
      Path:     /home/runner/.docker/cli-plugins/docker-compose
  Server:
   Containers: 1
    Running: 1
    Paused: 0
    Stopped: 0
   Images: 1
   Server Version: 28.2.2
   Storage Driver: overlay2
    Backing Filesystem: xfs
    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
   CDI spec directories:
    /etc/cdi
    /var/run/cdi
   Swarm: inactive
   Runtimes: runc io.containerd.runc.v2
   Default Runtime: runc
   Init Binary: docker-init
   containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
   runc version: v1.2.6-0-ge89a299
   init version: de40ad0
   Security Options:
    seccomp
     Profile: builtin
    cgroupns
   Kernel Version: 6.1.134
   Operating System: Alpine Linux v3.22 (containerized)
   OSType: linux
   Architecture: x86_64
   CPUs: 16
   Total Memory: [30](https://github.com/PII/PII/actions/runs/15829363608/job/44617836286?pr=26309#step:7:32).79GiB
   Name: arc-runner-set-amd64-8c-zjfb5-runner-nhv7m
   ID: cb10c906-1723-4f6d-9863-8f6679a61d67
   Docker Root Dir: /var/lib/docker
   Debug Mode: false
   Username: charlessortlist
   Experimental: false
   Insecure Registries:
    ::1/128
    127.0.0.0/8
   Live Restore Enabled: false
   Product License: Community Engine
  WARNING: bridge-nf-call-iptables is disabled

Anything else?

Thanks for your time, and for maintaining this awesome product!

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions